Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
hex to array buffer
(version: 0)
convert hex to array buffer
Comparing performance of:
regex match vs parseInt 16
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var hexVal = 'ed0c356af33bb022afe7c5f8557ad89c'; function hexToArrayBuffer(hex) { return new Uint8Array(hex.match(/[\da-f]{2}/gi).map((h) => { return parseInt(h, 16); })).buffer; } function hexStringToUint8Array(hexString) { var arrayBuffer = new Uint8Array(hexString.length / 2); for (var i = 0; i < hexString.length; i += 2) { var byteValue = parseInt(hexString.substr(i, 2), 16); arrayBuffer[i / 2] = byteValue; } return arrayBuffer; }
Tests:
regex match
hexToArrayBuffer(hexVal)
parseInt 16
hexStringToUint8Array(hexVal)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex match
parseInt 16
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0
Browser/OS:
Chrome 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regex match
388084.8 Ops/sec
parseInt 16
1206874.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its components. **Benchmark Definition JSON** The benchmark definition JSON contains information about the test case, including: * `Name`: The name of the test case. * `Description`: A brief description of what the test case is trying to measure. * `Script Preparation Code`: A JavaScript code snippet that sets up the test case. This includes the `hexToArrayBuffer` and `hexStringToUint8Array` functions, which are used to convert hexadecimal strings to Uint8Arrays. * `Html Preparation Code`: An empty string, indicating that no HTML preparation code is required for this benchmark. **Individual Test Cases** The benchmark definition JSON also contains two individual test cases: * The first test case measures the performance of converting a hexadecimal string to an array buffer using the `hexToArrayBuffer` function. * The second test case measures the performance of converting a hexadecimal string to a Uint8Array using the `parseInt` function with base 16 (i.e., `parseInt(16)`). **Options Compared** The two test cases compare different approaches for converting hexadecimal strings to arrays or Uint8Arrays: 1. `hexToArrayBuffer`: This approach uses a custom function to convert the hexadecimal string to an array buffer. 2. `parseInt 16`: This approach uses the built-in `parseInt` function with base 16 (i.e., `parseInt(16)`). **Pros and Cons** Here are some pros and cons of each approach: * `hexToArrayBuffer`: + Pros: Customizable, allows for more control over the conversion process. + Cons: May be slower than built-in functions due to the overhead of custom function calls. * `parseInt 16`: + Pros: Built-in function is likely to be faster and more efficient. + Cons: Limited control over the conversion process. **Library Used** There is no explicit library used in the benchmark definition JSON. However, the `Uint8Array` class is a built-in JavaScript object, and the `parseInt` function with base 16 is also a built-in function. **Special JS Feature/Syntax** No special JavaScript features or syntax are used in this benchmark. **Other Alternatives** Other alternatives for converting hexadecimal strings to arrays or Uint8Arrays include: * Using the `fromHex` method of the `Uint8Array` class (available in some browsers). * Using a third-party library like `hex-to-array-buffer`. * Using a native module like `libuv` or `node-ffi` to perform the conversion. Keep in mind that these alternatives may have different performance characteristics and trade-offs, depending on the specific use case and requirements.
Related benchmarks:
parse hex-string to 'bytes like object' (Uint8Array) in javascript
array buffer to hex conversion
array buffer to hex conversion 2
sha1-js-rusha-vs-native-10mb
Comments
Confirm delete:
Do you really want to delete benchmark?