Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Normalize digits
(version: 7)
Comparing performance of:
Map vs one liner vs one liner swapped vs ES6 for loop vs Using object vs regex normalize vs regex normalize swapped
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var str = "150721"; var DIGITS = new Map([ ["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["\uFF10", "0"], // Fullwidth digit 0 ["\uFF11", "1"], // Fullwidth digit 1 ["\uFF12", "2"], // Fullwidth digit 2 ["\uFF13", "3"], // Fullwidth digit 3 ["\uFF14", "4"], // Fullwidth digit 4 ["\uFF15", "5"], // Fullwidth digit 5 ["\uFF16", "6"], // Fullwidth digit 6 ["\uFF17", "7"], // Fullwidth digit 7 ["\uFF18", "8"], // Fullwidth digit 8 ["\uFF19", "9"], // Fullwidth digit 9 ["\u0660", "0"], // Arabic-indic digit 0 ["\u0661", "1"], // Arabic-indic digit 1 ["\u0662", "2"], // Arabic-indic digit 2 ["\u0663", "3"], // Arabic-indic digit 3 ["\u0664", "4"], // Arabic-indic digit 4 ["\u0665", "5"], // Arabic-indic digit 5 ["\u0666", "6"], // Arabic-indic digit 6 ["\u0667", "7"], // Arabic-indic digit 7 ["\u0668", "8"], // Arabic-indic digit 8 ["\u0669", "9"], // Arabic-indic digit 9 ["\u06F0", "0"], // Eastern-Arabic digit 0 ["\u06F1", "1"], // Eastern-Arabic digit 1 ["\u06F2", "2"], // Eastern-Arabic digit 2 ["\u06F3", "3"], // Eastern-Arabic digit 3 ["\u06F4", "4"], // Eastern-Arabic digit 4 ["\u06F5", "5"], // Eastern-Arabic digit 5 ["\u06F6", "6"], // Eastern-Arabic digit 6 ["\u06F7", "7"], // Eastern-Arabic digit 7 ["\u06F8", "8"], // Eastern-Arabic digit 8 ["\u06F9", "9"], // Eastern-Arabic digit 9 ]); var DIGITz = { "0": "0", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5", "6": "6", "7": "7", "8": "8", "9": "9", "\uFF10": "0", // Fullwidth digit 0 "\uFF11": "1", // Fullwidth digit 1 "\uFF12": "2", // Fullwidth digit 2 "\uFF13": "3", // Fullwidth digit 3 "\uFF14": "4", // Fullwidth digit 4 "\uFF15": "5", // Fullwidth digit 5 "\uFF16": "6", // Fullwidth digit 6 "\uFF17": "7", // Fullwidth digit 7 "\uFF18": "8", // Fullwidth digit 8 "\uFF19": "9", // Fullwidth digit 9 "\u0660": "0", // Arabic-indic digit 0 "\u0661": "1", // Arabic-indic digit 1 "\u0662": "2", // Arabic-indic digit 2 "\u0663": "3", // Arabic-indic digit 3 "\u0664": "4", // Arabic-indic digit 4 "\u0665": "5", // Arabic-indic digit 5 "\u0666": "6", // Arabic-indic digit 6 "\u0667": "7", // Arabic-indic digit 7 "\u0668": "8", // Arabic-indic digit 8 "\u0669": "9", // Arabic-indic digit 9 "\u06F0": "0", // Eastern-Arabic digit 0 "\u06F1": "1", // Eastern-Arabic digit 1 "\u06F2": "2", // Eastern-Arabic digit 2 "\u06F3": "3", // Eastern-Arabic digit 3 "\u06F4": "4", // Eastern-Arabic digit 4 "\u06F5": "5", // Eastern-Arabic digit 5 "\u06F6": "6", // Eastern-Arabic digit 6 "\u06F7": "7", // Eastern-Arabic digit 7 "\u06F8": "8", // Eastern-Arabic digit 8 "\u06F9": "9", // Eastern-Arabic digit 9 };
Tests:
Map
let result = ''; for (let i = 0, n = str.length; i < n; ++i) { result += DIGITS.get(str[i]); }
one liner
str.normalize("NFKC").replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15);
one liner swapped
str.replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15).normalize("NFKC");
ES6 for loop
let result = ''; for (let letter of str) { result += DIGITS.get(letter); }
Using object
let result = ''; for (let letter of str) { result += DIGITz[letter]; }
regex normalize
str.replace(/[\uFF10-\uFF19]/g,a=>a.charCodeAt(a.charCodeAt(0)-0xfee0)).replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15);
regex normalize swapped
str.replace(/[٠-٩۰-۹]/g,a=>a.charCodeAt(0)&15).replace(/[\uFF10-\uFF19]/g,a=>a.charCodeAt(a.charCodeAt(0)-0xfee0));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
Map
one liner
one liner swapped
ES6 for loop
Using object
regex normalize
regex normalize swapped
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):
It seems like you're trying to analyze the benchmark results of some code transformations related to string processing in JavaScript. To provide a helpful answer, I'll need to parse and analyze the provided data. However, since the actual data is not included in your text, I'll assume that you want me to extract relevant information from the given "Benchmark result" string. From the string, it appears that there are four test cases: 1. **one liner**: With two sub-cases: `one liner` and `one liner swapped`. 2. **ES6 for loop**. 3. **Using object**. 4. **regex normalize** and its swapped version. To answer your question, I'll need to know what you're specifically looking for in the benchmark results. Are you interested in: * The execution time for each test case? * The best-performing test case? * A comparison between the different approaches (e.g., which one is faster)? * Something else? Please clarify your requirements, and I'll do my best to provide a helpful answer based on the provided data.
Related benchmarks:
JSON stringification versus simple map
lodash flatmap long
lodash flatmap longest
Bitwise NOT VS Number
Comments
Confirm delete:
Do you really want to delete benchmark?