Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sha1-js-rusha-vs-native-10mb
(version: 0)
Comparing performance of:
rusha vs native
Created:
2 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rusha@0.8.14/dist/rusha.min.js"></script>
Script Preparation code:
var data = new Uint32Array(10*1024*1024); var dataBuffer = new Uint8Array(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:
rusha
Rusha.createHash().update(dataBuffer).digest('hex');
native
crypto.subtle.digest("SHA-1", dataBuffer ).then(function (hash) {console.log(hex(hash));});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
rusha
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
rusha
27.5 Ops/sec
native
493.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark is comparing two approaches to calculate the SHA-1 hash of a large buffer (10MB) using JavaScript: 1. **Rusha**: A JavaScript library that provides a simplified way to create hashes and digests. 2. **Native**: Using the Web Cryptography API's `crypto.subtle.digest()` function, which is part of the browser's implementation. **Options Compared** The two options being compared are: * **Rusha.createHash().update(dataBuffer).digest('hex')**: This method creates a new hash object, updates it with the data buffer, and then converts the resulting digest to a hexadecimal string. * **crypto.subtle.digest("SHA-1", dataBuffer).then(function (hash) { console.log(hex(hash)); })**: This method uses the Web Cryptography API's `crypto.subtle.digest()` function to calculate the SHA-1 hash of the data buffer, and then processes the resulting digest using a helper function (`hex`) to convert it to a hexadecimal string. **Pros and Cons** * **Rusha**: + Pros: Simplified interface, easy to use, and likely to be more performant due to its optimized implementation. + Cons: May have limitations or constraints on its usage (e.g., limited support for certain hash algorithms), and may not be as widely supported as the native Web Cryptography API implementation. * **Native**: + Pros: Wide adoption and support across browsers, allowing for cross-platform testing. The Web Cryptography API is designed to provide a secure way to calculate hashes and digests. + Cons: Requires more boilerplate code (e.g., creating a `crypto.subtle.digest()` promise), which may impact performance. **Library** * **Rusha**: A lightweight JavaScript library that provides an easy-to-use interface for creating hashes and digests. It's likely designed to be fast, efficient, and optimized for performance. **Special JS Features or Syntax** None mentioned in the provided benchmark definition. **Other Considerations** When choosing between these two options, consider your specific use case: * If you need a lightweight, easy-to-use solution with potential performance benefits, choose Rusha. * If you require a widely supported, secure solution for cross-platform testing and hashing, choose the native Web Cryptography API implementation (using `crypto.subtle.digest()`). **Alternatives** Other alternatives to consider when calculating hashes or digests in JavaScript: 1. **Crypto-JS**: A popular, high-level JavaScript library that provides an easy-to-use interface for various cryptographic operations. 2. **Web Crypto API's crypto.subtle functions**: While similar to `crypto.subtle.digest()`, these functions provide more comprehensive support for cryptographic primitives, such as encryption and decryption. In summary, the Rusha benchmark compares two approaches to calculate SHA-1 hashes using JavaScript: a lightweight library (Rusha) versus the native Web Cryptography API implementation (using `crypto.subtle.digest()`). Consider your specific use case when choosing between these options.
Related benchmarks:
Sha-xxx
sha1-js
sha1-js-pref
Digest Sha-1
Comments
Confirm delete:
Do you really want to delete benchmark?