Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
CP437 decode 80000
(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 = 80000; 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):
Let's break down the benchmark and its options. **Benchmark Definition** The benchmark is defined by a JavaScript function that takes an array of bytes as input. The function, named `decodeAppend`, appends the characters represented by the bytes in the array to a string using the CP437 encoding. **Options Compared** There are four different implementations of the `decodeAppend` function: 1. `decodeFromCharCode2(arr, chunk)` 2. `decodeFromCharCode2(arr, 1000)` 3. `decodeFromCharCode2(arr, 10000)` 4. `decodeFromCharCode2(arr, 10)` These functions differ in their approach to decoding the array of bytes: * `decodeFromCharCode2` with no arguments (or a fixed chunk size) is not provided as an option. * `decodeFromCharCode2` with a variable chunk size (1000, 10000, or 10). This function processes the input array in chunks and decodes each chunk separately. **Pros and Cons** Here are some pros and cons of each approach: 1. **Fixed chunk size**: `decodeFromCharCode2(arr, chunk)` * Pros: + May be faster due to reduced overhead from string concatenation. + Can take advantage of caching mechanisms. * Cons: + May result in slower performance for smaller input arrays or larger chunks. + Requires careful tuning of the chunk size for optimal performance. 2. **Variable chunk size**: `decodeFromCharCode2(arr, 1000)`, `decodeFromCharCode2(arr, 10000)`, and `decodeFromCharCode2(arr, 10)` * Pros: + Can adapt to varying input array sizes and chunk requirements. + May improve performance for larger inputs or smaller chunks. * Cons: + May incur additional overhead due to string concatenation and processing in chunks. + Requires more complex logic to handle different chunk sizes. **CP437 Encoding** The CP437 encoding is a character encoding standard that maps each byte in the input array to a single Unicode code point. This encoding is commonly used for compatibility with older systems, but it may not provide optimal performance due to its limited range (256 characters) and variable-width representation of some characters. In summary, the benchmark compares different implementations of the `decodeAppend` function that process the input array in varying chunk sizes. The choice of approach depends on the specific requirements and constraints of the use case.
Related benchmarks:
Lodash vs vanila 2
CP437 decode
CP437 decode 8000
Random hex string generation benchmark
Comments
Confirm delete:
Do you really want to delete benchmark?