Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Compare digest performance
(version: 0)
Comparing performance of:
crypto.subtle.digest("SHA-512") vs xxHash64
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src=" https://cdn.jsdelivr.net/npm/xxhashjs@0.2.2/build/xxhash.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:
crypto.subtle.digest("SHA-512")
crypto.subtle.digest("SHA-512", dataBuffer ).then(function (hash) {console.log(hex(hash));});
xxHash64
console.log("xxHash:", XXH.h32().update(dataBuffer).digest().toString(16));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
crypto.subtle.digest("SHA-512")
xxHash64
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
crypto.subtle.digest("SHA-512")
336720.3 Ops/sec
xxHash64
95925.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an explanation of the provided benchmark, comparing different approaches for digest performance. **Benchmark Overview** The benchmark compares two methods for calculating a SHA-512 hash using JavaScript: `crypto.subtle.digest()` and `xxHash`. The goal is to determine which method performs better in terms of execution speed. **Options Compared** There are two options being compared: 1. **`crypto.subtle.digest()`**: This method uses the Web Cryptography API to calculate a SHA-512 hash. It takes advantage of hardware acceleration to perform the hashing operation. 2. **`xxHash64`**: This is a JavaScript implementation of the xxHash algorithm, a fast and compact hashing function. **Pros and Cons** ### `crypto.subtle.digest()` Pros: * Leverages Web Cryptography API for hardware acceleration * Typically faster than software-based implementations * More secure due to the use of cryptographic primitives Cons: * May require additional setup and configuration * Can be slower in JavaScript engines without hardware acceleration (e.g., older browsers) * Limited compatibility with older browsers or environments that don't support Web Cryptography API ### `xxHash64` Pros: * Fast and compact implementation * Suitable for a wide range of platforms and browsers * Easy to integrate into existing codebases Cons: * May not be as secure as `crypto.subtle.digest()` due to the use of a non-cryptographic algorithm * Can be slower than `crypto.subtle.digest()` in JavaScript engines with hardware acceleration **Library: SubtleCrypto** The `SubtleCrypto` library is used by `crypto.subtle.digest()`. It provides a set of cryptographic primitives and APIs for secure data processing. The `digest()` method calculates the SHA-512 hash of a given input buffer. **Special JS Feature/Syntax: Web Cryptography API** The Web Cryptography API (W3C) enables developers to use cryptographic primitives in web applications. It allows for secure data processing, encryption, and decryption, among other features. The `crypto.subtle.digest()` method leverages this API to perform SHA-512 hashing. **Other Alternatives** Some alternative hashing algorithms that could be used as benchmarks include: * `crypto.subtle.digest('SHA-256')`: This option uses a different cryptographic hash function, but still benefits from hardware acceleration. * `sha512.js`: A pure JavaScript implementation of the SHA-512 algorithm, which may not benefit from Web Cryptography API or hardware acceleration. Note that the choice of hashing algorithm and implementation depends on the specific use case and requirements.
Related benchmarks:
Sha256
Sha256
dsha256
Hashing Benchmarks
Comments
Confirm delete:
Do you really want to delete benchmark?