Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
web-crypto
(version: 3)
Comparing performance of:
sha512 vs sha256
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
async function sign256(path, secret) { const encoder = new TextEncoder(); const data = encoder.encode(path); const key = await crypto.subtle.importKey( 'raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'] ); const signature = await crypto.subtle.sign('HMAC', key, data); const hashArray = Array.from(new Uint8Array(signature)); const base64Hash = btoa(String.fromCharCode(...hashArray)) return base64Hash + '/' + path; } async function sign512(path, secret) { const encoder = new TextEncoder(); const data = encoder.encode(path); const key = await crypto.subtle.importKey( 'raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-512' }, false, ['sign'] ); const signature = await crypto.subtle.sign('HMAC', key, data); const hashArray = Array.from(new Uint8Array(signature)); const base64Hash = btoa(String.fromCharCode(...hashArray)) return base64Hash + '/' + path; }
Tests:
sha512
sign512('500x500/top/raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png', 'mysecret').then(result => result)
sha256
sign256('500x500/top/raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png', 'mysecret').then(result => result)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
sha512
sha256
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
sha512
619056.4 Ops/sec
sha256
636698.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain what's being tested in this benchmark. **Benchmark Overview** This benchmark compares the performance of two different HMAC (Keyed-Hash Message Authentication Code) signatures: SHA-256 and SHA-512, using the Web Cryptography API. The benchmark is designed to measure the execution time of these signature operations on a specific input image file. **Options being compared** There are two options being compared: 1. **SHA-256**: This option uses the SHA-256 hash function with a key size of 256 bits. 2. **SHA-512**: This option uses the SHA-512 hash function with a key size of 512 bits. **Pros and Cons of each approach** * **SHA-256**: + Pros: Generally faster than SHA-512, requiring less computational resources and memory. + Cons: Less secure than SHA-512, as it's more susceptible to collisions and preimages. * **SHA-512**: + Pros: More secure than SHA-256, providing better protection against attacks like hash collisions. + Cons: Slower than SHA-256, requiring more computational resources and memory. **Library usage** The Web Cryptography API is used in this benchmark to create HMAC signatures. The `crypto.subtle` module is a part of the Web Cryptography API, which provides a way to perform cryptographic operations like key generation, encryption, and signing. **Special JS feature or syntax** This benchmark does not use any special JavaScript features or syntax beyond what's provided by the Web Cryptography API. It only relies on standard JavaScript functions like `async/await`, `TextEncoder`, and `btoa`. **Other alternatives** If you were to rewrite this benchmark using alternative approaches, some options might include: * Using a different cryptographic library or framework (e.g., OpenSSL, NaCl). * Implementing the HMAC signature calculation manually without relying on the Web Cryptography API. * Using a different hash function or key size for comparison. However, these alternatives would likely introduce significant changes to the benchmark's design and implementation.
Related benchmarks:
Sha256
Sha256-2
sha256-js
sha256-js twin
Comments
Confirm delete:
Do you really want to delete benchmark?