Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ArrayBuffer
(version: 0)
Comparing performance of:
Encoder vs Simple
Created:
9 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var str = "aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7aa34a5b6c5acb67acb5acb678acb6ac4b5a6c7b5a4c3b45a67c8b76a54cb34a5c6b7"; var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var encoder = new TextEncoder(); function _base64ToArrayBufferOptimized(base64) { return encoder.encode(base64); } function _base64ToArrayBuffer(base64) { var binary_string = window.atob(base64); var len = binary_string.length; var bytes = new Uint8Array( len ); for (var i = 0; i < len; i++) { bytes[i] = binary_string.charCodeAt(i); } return bytes.buffer; }
Tests:
Encoder
_base64ToArrayBufferOptimized(str);
Simple
_base64ToArrayBuffer(str);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Encoder
Simple
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/135.2 Mobile/15E148 Safari/605.1.15
Browser/OS:
Mobile Safari 18 on iOS 18.3.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Encoder
5024713.0 Ops/sec
Simple
656130.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and its results in a way that's easy to understand, even for those without deep knowledge of JavaScript. **What is being tested?** The provided JSON represents two microbenchmarks: `ArrayBuffer` and two test cases named "Encoder" and "Simple". The tests are designed to measure the performance of converting base64-encoded strings to ArrayBuffer objects. **Options compared** Two options are compared: 1. **_base64ToArrayBufferOptimized(base64)**: This function uses the `TextEncoder` API, which is a modern way to work with Uint8Array and ArrayBuffers in JavaScript. 2. **_base64ToArrayBuffer(base64)**: This function uses the `window.atob()` method, which is an older way to decode base64-encoded strings. **Pros and Cons of each approach** **TextEncoder API (Optimized):** Pros: * More efficient and modern * Better support for large datasets and streaming data Cons: * Requires a relatively new browser version (Firefox 130 or later) * May have performance variations depending on the browser's implementation **`window.atob()` method:** Pros: * Widespread support across older browsers and versions * Simpler to implement Cons: * Less efficient, especially for large datasets * May not work well with streaming data **Other considerations** * The tests use a large base64-encoded string (`str`) as input, which may affect the results. * The `TextEncoder` API is generally faster and more efficient than using `window.atob()`. **Library used** The `TextEncoder` API is used in the optimized function. It's a built-in JavaScript library that provides a way to encode strings into Uint8Array objects. **Special JS feature or syntax** None mentioned, as both test cases use standard JavaScript features. **Benchmark preparation code** The provided script preparation code generates a large base64-encoded string (`str`) and defines two functions: `_base64ToArrayBufferOptimized` and `_base64ToArrayBuffer`. These functions are then used in the benchmark definitions. **Alternatives** If you need to measure performance of converting base64-encoded strings to ArrayBuffers in older browsers, you may want to consider using a library like `base64-js`, which provides a more efficient and modern way to work with base64 encoding. Additionally, if you're interested in exploring other approaches or testing different libraries, you can look into: * Using Web Workers to parallelize the tests * Measuring performance using other benchmarking tools, such as WebPageTest or Apache JMeter * Testing different input sizes and scenarios
Related benchmarks:
String.fromCharCode & btoa vs base64ArrayBuffer function
String.fromCharCode & btoa vs base64ArrayBuffer function FIXED
String.fromCharCode & btoa vs base64ArrayBuffer function FIXED ON LARGE ARRAY
Base64 encode native func vs readAsDataURL()
Comments
Confirm delete:
Do you really want to delete benchmark?