Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sha256-js twin
(version: 0)
Comparing performance of:
forge vs native vs sjcl vs crypto vs cryptico
Created:
2 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/cryptico/0.0.1343522940/cryptico.min.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); var data = '1700029536090896958:168225279115264:181419418648576:15921905'; var dataBuffer = new TextEncoder().encode(data); // 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.sha256.create().update(data).digest()
native
crypto.subtle.digest("SHA-256", dataBuffer ).then(function (hash) {console.log(hex(hash));});
sjcl
sjcl.hash.sha256.hash(data);
crypto
CryptoJS.SHA256(data);
cryptico
SHA256(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
forge
native
sjcl
crypto
cryptico
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is tested?** MeasureThat.net provides a JSON file that represents a benchmark, which in this case is the calculation of the SHA-256 hash of a given string. The benchmark tests four different approaches: 1. **Native**: Uses the Web API `crypto.subtle.digest()` to calculate the SHA-256 hash. 2. **SJCL**: Utilizes the SJCL (Simple JavaScript Cryptography Library) library, specifically the `sjcl.hash.sha256` function, to calculate the SHA-256 hash. 3. **CryptoJS**: Employs the CryptoJS library, which has a `SHA256` function, to calculate the SHA-256 hash. 4. **Forge**: Uses the Forge library, which provides a `SHA256` function, to calculate the SHA-256 hash. **Options compared** Each approach uses a different implementation to calculate the SHA-256 hash: * Native: Uses the Web API's `crypto.subtle.digest()` function, which is a built-in implementation of the SHA-256 algorithm. * SJCL: Implements the SHA-256 algorithm using native code, providing a more optimized and secure solution. * CryptoJS: Provides a pre-built SHA-256 function that can be used to calculate hashes. * Forge: Offers a `SHA256` function that uses a combination of built-in implementations and native code for optimal performance. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * Native: + Pros: Built-in implementation, optimized for performance, secure. + Cons: Limited control over implementation details, may not be available on all browsers. * SJCL: + Pros: Optimized for performance, secure, provides more control over implementation details. + Cons: Requires additional dependencies (SJCL library), may have slightly slower performance compared to native implementation. * CryptoJS: + Pros: Easy to use, provides a simple API, can be used in older browsers that don't support Web APIs. + Cons: Not optimized for performance, may not be as secure as native or SJCL implementations. * Forge: + Pros: Optimized for performance, secure, provides more control over implementation details. + Cons: Requires additional dependencies (Forge library), may have slightly slower performance compared to native implementation. **Libraries and their purpose** Here are the libraries used in this benchmark: * **SJCL**: A simple JavaScript cryptography library that provides a wide range of cryptographic functions, including hash functions like SHA-256. It's designed for ease of use and high performance. * **CryptoJS**: A popular JavaScript library for cryptographic operations, providing an easy-to-use API for various algorithms, including SHA-256. However, it may not be as optimized or secure as native implementations. * **Forge**: A C++ library that provides a wide range of cryptographic functions, including hash functions like SHA-256. It's designed for high performance and security, but requires additional dependencies (the JavaScript wrapper). **Special JS feature/syntax** This benchmark does not use any special JavaScript features or syntax that are specific to modern browsers. **Alternatives** If you're interested in exploring alternative approaches, here are a few options: * **Web Cryptography API**: This is a newer API that provides more comprehensive support for cryptographic operations, including hash functions. * **Browser-specific implementations**: Some browsers (e.g., Chrome) provide their own implementation of the SHA-256 algorithm, which can be used instead of the Web API or a library like SJCL or Forge.
Related benchmarks:
Sha256
Sha256
Sha256-2
Sha256-Hex-Effect
sha256-js
Comments
Confirm delete:
Do you really want to delete benchmark?