Coder Social home page Coder Social logo

Comments (2)

etienne-martin avatar etienne-martin commented on May 25, 2024

Hi Marcin,

I just updated my test with the latest version of CryptoSwift and I'm now getting 5255ms on my machine. Far better than the 24366ms from the Swift 3 version.

Here's the code I use for the benchmark:

import Foundation 
import CryptoSwift 

extension Date {
    func timestamp() -> Int64 {
        return Int64(self.timeIntervalSince1970 * 1000)
    }
}

let length = 10000000 // 10MB
let bytes = [UInt32](repeating: 0, count: length).map { _ in random() }
let data = Array(Data(bytes: bytes, count: length))

let start = Date().timestamp()

do {
    let aes = try AES(key: "passwordpasswordpasswordpassword", iv: "drowssapdrowssap") // aes256
    _ = try aes.encrypt(data)
    
    print(Date().timestamp()-start)
    
} catch { }

You can try the snippet above on swiftplayground.run, it takes around 1600ms to complete.

I must be doing something wrong because it's still far from 753ms.

I updated the doc to reflect the new number but I'm still curious about why I'm getting such a big difference in speed.

You say that maybe I'm testing with the debug build. Can you show me a way to check which build of CryptoSwift I use in my Xcode project?

Thanks for letting me know.

from webcrypto.swift.

krzyzanowskim avatar krzyzanowskim commented on May 25, 2024

The values don't look right for me. The online playground runs on the slowest possible Linux virtual machine (currently) that definitely shouldn't be 4 times faster than i7 MacBook. The playground isn't also set up for the performance.

Let's use the same setup:

$ git clone https://github.com/krzyzanowskim/CryptoSwift.git
$ git checkout tests/performance

Open the CryptoSwift.xcodeproj with Xcode 9.2, and run the testAESEncryptPerformance test on the mac:

performance_test

Unfortunately, the SPM doesn't allow to adjust all the settings, but it can be run like this:

$ swift test -c release --filter "CryptoSwiftTests.AESTests/testAESEncryptPerformance" -Xswiftc -enable-testing -Xswiftc -Ounchecked -Xswiftc -whole-module-optimization -Xswiftc -no-link-objc-runtime -Xswiftc -enforce-exclusivity=none -Xswiftc -gnone

screen shot 2018-02-07 at 09 57 08

from webcrypto.swift.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.