Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hashing performance with long strings
(version: 0)
Comparing performance of:
SHA-1 vs SHA-256
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function generateStringifiedDummyConfigTO(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } var lengthOfStringifiedConfigTOWith2000Filters = 70*2000; var dummyStringifiedConfigTO = generateStringifiedDummyConfigTO(lengthOfStringifiedConfigTOWith2000Filters); async function generateConfigId(hashAlgorithm, stringifiedConfigTO) { const encodedConfig = new TextEncoder().encode(stringifiedConfigTO); const hashBuffer = await crypto.subtle.digest(hashAlgorithm, encodedConfig); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); return hashHex; }
Tests:
SHA-1
generateConfigId('SHA-1', dummyStringifiedConfigTO) .then(hashHex => console.log(hashHex));
SHA-256
generateConfigId('SHA-256', dummyStringifiedConfigTO) .then(hashHex => console.log(hashHex));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
SHA-1
SHA-256
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 break down what's being tested in this benchmark. **What is being tested?** The provided JSON represents two individual test cases, each testing the performance of different hash algorithms (SHA-1 and SHA-256) when hashing long strings using the `generateConfigId` function. The input data for both tests comes from a pre-generated string (`dummyStringifiedConfigTO`) that's created with a random combination of characters. **Options being compared** The two options being compared are: 1. **SHA-1**: a cryptographic hash algorithm designed to produce a 160-bit (20-byte) hash value. 2. **SHA-256**: another cryptographic hash algorithm, which produces a 256-bit (32-byte) hash value. **Pros and Cons of each approach** * **SHA-1**: + Pros: relatively fast (fastest in this test case), widely supported and implemented. + Cons: considered insecure for protecting data integrity due to its vulnerability to collisions (e.g., the "Collision Attack") and preimage attacks. * **SHA-256**: + Pros: more secure than SHA-1, widely used and accepted for data protection. + Cons: slower than SHA-1. **Library usage** The `generateConfigId` function uses two libraries: 1. **`TextEncoder`**: a built-in JavaScript library that provides an efficient way to encode text into Uint8Array. 2. **`crypto.subtle.digest`**: another built-in JavaScript library, part of the Web Cryptography API (W3C), which provides support for cryptographic hash functions. **Special JS feature or syntax** The test case uses: 1. **Promises**: a syntax used to handle asynchronous operations in JavaScript. In this case, `async/await` is used to simplify code readability. 2. **`crypto.subtle.digest`**: a Web Cryptography API method that's not explicitly supported by all browsers. However, most modern browsers (including Opera 86) support it. **Other alternatives** For comparing hash algorithms' performance, alternative approaches could include: 1. Using existing benchmarking frameworks like Benchmark.js or jsperf. 2. Utilizing built-in JavaScript functions like `crypto.createHash()` (for Node.js) or `window.crypto.subtle.digest()` (in browser-based environments). 3. Implementing a custom benchmarking loop using plain JavaScript loops. Note that each alternative approach might have its own set of pros and cons, depending on the specific requirements and constraints of your project.
Related benchmarks:
FastStringMap test3
TextEncoder vs String hash v2
hashCode reduce vs while
Simple string compare vs SHA-1 hash
Comments
Confirm delete:
Do you really want to delete benchmark?