Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
CP437 decode 8000
(version: 0)
Comparing performance of:
append string vs from char code vs chunk 100 vs chunk 1000 vs chunk 10000 vs chunk 10
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var n = 8000; var arr = new Uint8Array(n); for (let i = 0; i < n; ++i) { arr[i] = (Math.random() * 255) | 0; } const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split(""); function convert_in_place(s) { for (let k = 0; k < s.length; k++) s[k] = CP437[s[k]]; return s; } function convert(buf) { return convert_in_place(buf.slice()); } function decodeAppend(buf) { let result = ""; for (let indexCharacter = 0; indexCharacter < buf.length; indexCharacter++) { result += CP437[buf[indexCharacter]]; } return result; } function decodeFromCharCode(buf) { const s = convert(buf); return String.fromCharCode.apply(null, s); } function decodeFromCharCode2(buf, chunk) { let str = ""; let pad = new Uint8Array(chunk); for(let k = 0; k < buf.length; k += chunk) { const remaining = buf.length - k; for (let i = 0; i < Math.min(chunk, remaining); i++) pad[i] = CP437[buf[k + i]]; str += String.fromCharCode.apply(null, remaining < chunk ? pad.subarray(0, remaining) : pad); } return str; }
Tests:
append string
decodeAppend(arr)
from char code
decodeFromCharCode(arr)
chunk 100
decodeFromCharCode2(arr, 100)
chunk 1000
decodeFromCharCode2(arr, 1000)
chunk 10000
decodeFromCharCode2(arr, 10000)
chunk 10
decodeFromCharCode2(arr, 10)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
append string
from char code
chunk 100
chunk 1000
chunk 10000
chunk 10
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):
I'll break down the provided JSON and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark defines four functions for decoding strings from a buffer: 1. `decodeAppend(buf)`: appends the decoded string to the original buffer. 2. `decodeFromCharCode(buf)`: converts the buffer to an array of character codes using `String.fromCharCode`. 3. `decodeFromCharCode2(buf, chunk)`: similar to 2, but decodes in chunks of a specified size. **Test Cases** The test cases compare the performance of these four decoding functions: 1. `append string` (decodeAppend) 2. `from char code` (decodeFromCharCode) 3. `chunk 100` 4. `chunk 10` 5. `chunk 1000` 6. `chunk 10000` **Library: CP437** The library `CP437` is used to map character codes to their corresponding Unicode characters. Here's a brief explanation of the CP437 library: * CP437 is a character encoding standard for Windows systems. * It defines a set of ASCII-like characters, including Unicode characters in the range U+0080 to U+00FF. **Functionality Comparison** Here's a comparison of the four functions and their pros/cons: 1. `decodeAppend(buf)`: This function appends the decoded string to the original buffer. The pros are that it's simple and efficient, but the cons are that it can lead to buffer overflows if the decoded string is longer than the remaining buffer space. 2. `decodeFromCharCode(buf)`: This function converts the buffer to an array of character codes using `String.fromCharCode`. The pros are that it's relatively fast and doesn't require a separate buffer for decoding. However, the cons are that it can lead to performance issues with large buffers or Unicode characters. 3. `decodeFromCharCode2(buf, chunk)`: This function is similar to 2, but decodes in chunks of a specified size. The pros are that it's more memory-efficient than 2 and can handle larger buffers without overflowing. However, the cons are that it may introduce additional overhead due to the chunking. 4. `chunk 10`, `chunk 100`, `chunk 1000`, and `chunk 10000`: These test cases compare the performance of each function with different buffer sizes. **Performance Comparison** The latest benchmark result shows that: * `decodeAppend(buf)` is the fastest, with an average execution rate of 4040.47 executions per second. * `decodeFromCharCode(buf)` is slower than `append string`, but faster than the chunking functions, with an average execution rate of 288.25 executions per second. * The chunking functions (`chunk 10`, `chunk 100`, and `chunk 1000`) have varying performance depending on the buffer size. Overall, the benchmark suggests that `decodeAppend(buf)` is the most efficient decoding function for this specific use case. However, the choice of decoding function may depend on the specific requirements of your application, such as memory constraints or performance considerations.
Related benchmarks:
Lodash vs vanila 2
CP437 decode
CP437 decode 80000
Random hex string generation benchmark
Comments
Confirm delete:
Do you really want to delete benchmark?