Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sha1-js
(version: 0)
Comparing performance of:
forge vs native vs sjcl vs cryptojs
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.6/sjcl.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/rusha/0.8.7/rusha.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.9.1/forge.min.js"></script>
Script Preparation code:
var data = new Uint32Array(1024); window.crypto.getRandomValues(data); var dataBuffer = new Uint8Array(data); data = String.fromCharCode.apply(null, dataBuffer); // src: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest function hex(buffer) { var hexCodes = []; var view = new DataView(buffer); for (var i = 0; i < view.byteLength; i += 4) { // Using getUint32 reduces the number of iterations needed (we process 4 bytes each time) var value = view.getUint32(i) // toString(16) will give the hex representation of the number without padding var stringValue = value.toString(16) // We use concatenation and slice for padding var padding = '00000000' var paddedValue = (padding + stringValue).slice(-padding.length) hexCodes.push(paddedValue); } // Join all the hex strings into one return hexCodes.join(""); }
Tests:
forge
forge.md.sha1.create().update(data).digest()
native
crypto.subtle.digest("SHA-1", dataBuffer ).then(function (hash) {console.log(hex(hash));});
sjcl
sjcl.hash.sha1.hash(data);
cryptojs
CryptoJS.SHA1(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
forge
native
sjcl
cryptojs
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:141.0) Gecko/20100101 Firefox/141.0
Browser/OS:
Firefox 141 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
forge
73425.5 Ops/sec
native
536835.6 Ops/sec
sjcl
0.0 Ops/sec
cryptojs
27942.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, comparing the performance of different libraries and implementations for various cryptographic algorithms. **Benchmark Definition JSON Explanation** The provided JSON defines a benchmark named "sha1-js". The script preparation code generates a random 1024-byte array using the `window.crypto.getRandomValues()` function and converts it to a hexadecimal string. The `hex` function is used to process the data and convert it into a SHA-1 hash. **Options Compared** The benchmark compares four different libraries/libraries-like implementations: 1. **Forge**: A JavaScript implementation of various cryptographic algorithms, including SHA-1. 2. **Native**: Uses the Web Cryptography API (W3C) to perform SHA-1 calculations directly on the browser's native cryptographic engine. 3. **Sjcl**: A small and fast library for cryptographic primitives, including SHA-1. 4. **CryptoJS**: A popular JavaScript library for cryptography, including SHA-1. **Pros and Cons of Each Approach** * **Forge**: Pros: Lightweight, easy to use, and well-maintained. Cons: May not be as performant as native implementations or dedicated cryptographic libraries like Sjcl or CryptoJS. * **Native (Web Cryptography API)**: Pros: Fastest and most secure way to perform cryptographic operations on the browser. Cons: Limited availability (some older browsers may not support it). * **Sjcl**: Pros: Small size, fast performance, and easy to use. Cons: May have limited features compared to dedicated libraries like Forge or CryptoJS. * **CryptoJS**: Pros: Feature-rich, well-maintained, and widely used. Cons: Larger size compared to Sjcl, and may not be as performant as native implementations. **Library Descriptions** 1. **Forge**: A JavaScript implementation of various cryptographic algorithms, including SHA-1. It provides a simple and easy-to-use API for common cryptographic tasks. 2. **Sjcl**: A small and fast library for cryptographic primitives, including SHA-1. It is designed to be lightweight and efficient while still providing robust security features. 3. **CryptoJS**: A popular JavaScript library for cryptography, including SHA-1. It provides a comprehensive set of cryptographic functions and tools for encryption, decryption, and hashing. **Special JS Features/Syntax** The benchmark uses some specialized JavaScript features and syntax: * `window.crypto.getRandomValues()`: A function that generates cryptographically secure random numbers. * `Web Cryptography API (W3C)**: A set of APIs that provide a way to perform cryptographic operations on the browser, such as generating keys, signing data, and verifying signatures. **Other Alternatives** If you're looking for alternative libraries or implementations for SHA-1 calculations, some options include: * **SHA-1.js**: A lightweight JavaScript implementation of the SHA-1 algorithm. * **Crypto-SHA-1**: A JavaScript library that provides an implementation of the SHA-1 algorithm along with other cryptographic primitives. Keep in mind that these alternatives may not be as performant or feature-rich as the libraries and implementations compared in the benchmark.
Related benchmarks:
Sha-xxx
sha1-js-pref
Sha512
sha1-js-rusha-vs-native-10mb
Comments
Confirm delete:
Do you really want to delete benchmark?