Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Encode vs Blobie
(version: 0)
Comparing performance of:
TextEncoder vs Blob
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
iterations = 1000; function randomStringGen(n) { let strings = []; for (let i = 0; i < n; i++) { let s = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); strings[i] = s; } return strings; } var randomStrings = randomStringGen(iterations); var encoder = new TextEncoder();
Tests:
TextEncoder
var j = 0; for (let i = 0; i < iterations; i++) { var str = randomStrings[i % iterations]; encoder.encode(str).length }
Blob
var j = 0; for (let i = 0; i < iterations; i++) { var str = randomStrings[i % iterations]; new Blob([str]).size }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
TextEncoder
Blob
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 138 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
TextEncoder
572.3 Ops/sec
Blob
1.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares two approaches for encoding strings: `TextEncoder` and creating a `Blob` object from a string. **Options compared:** Two options are compared: 1. **TextEncoder**: This is a built-in JavaScript API for encoding strings. It provides an efficient way to encode strings into various formats, such as UTF-8. 2. **Blob**: This creates a new blob (a binary file-like object) from the encoded string. **Pros and Cons of each approach:** * **TextEncoder**: + Pros: - Faster execution time due to its optimized encoding algorithm - More memory-efficient as it only encodes the actual data, without unnecessary padding or headers - Can be used for a variety of encoding formats, including UTF-8 + Cons: - Requires JavaScript engine support (most modern browsers have built-in support) - May not work in older browsers or environments without `TextEncoder` * **Blob**: + Pros: - Works across all browsers and environments with no additional setup required - Can be used for encoding binary data as well, not just text + Cons: - Slower execution time due to the overhead of creating a new blob object - May require more memory to store the encoded string **Library usage:** In this benchmark, no external libraries are explicitly mentioned. However, the `TextEncoder` API is built into modern JavaScript engines and is not considered a third-party library. **Special JS feature or syntax:** The benchmark uses the `for...of` loop (in the `Html Preparation Code`) to generate an array of random strings, which is a relatively recent feature introduced in ECMAScript 2015. This loop provides a concise way to iterate over arrays and is commonly used in modern JavaScript development. **Other alternatives:** If you need to compare encoding approaches with other options, some alternative methods could be: * Using the `Buffer` API (a more low-level, binary-based approach) * Utilizing WebAssembly (WASM) for optimized performance * Employing a third-party library like `js-base64` or `base64-js` for encoding and decoding strings Keep in mind that these alternatives may have different pros and cons compared to the `TextEncoder` and `Blob` approaches.
Related benchmarks:
Encode vs Blob
Encode vs Blob on large string
Encode vs Blob v2
Encode vs Blob v2.1
Comments
Confirm delete:
Do you really want to delete benchmark?