Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
I suppose you think we should write in assembly
(version: 0)
Comparing performance of:
split and join vs readable regex vs slice and append mess
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.dates = [ new Date(), new Date('1960-12-01'), new Date('3401-01-12') ].map((a) => (a.toISOString())); window.test1 = (isoString) => { isoString = isoString.split('T')[0].split('-'); return [isoString[1], isoString[2], isoString[0]].join('-'); }; let regex = /^(?<year>\d+)-(?<month>\d+)-(?<day>\d+)T.*$/; let replace = '$<month>-$<day>-$<year>'; window.test2 = (isoString) => (isoString.replace(regex, replace)); window.test3 = (isoString) => { isoString = isoString.slice(0, 10); return isoString.slice(8, 10) + '-' + isoString.slice(5, 7) + '-' + isoString.slice(0, 4); };
Tests:
split and join
for (let isoString of dates) test1(isoString);
readable regex
for (let isoString of dates) test2(isoString);
slice and append mess
for (let isoString of dates) test3(isoString);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
split and join
readable regex
slice and append mess
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 provided benchmarking data and explain what's being tested. **Benchmark Definition JSON** The `Script Preparation Code` section defines three functions: `test1`, `test2`, and `test3`. These functions appear to manipulate date strings in ISO format. Here's a brief overview of each function: 1. `test1`: Takes an ISO string, splits it into year, month, and day parts, and then joins them back together in the format "day-month-year". 2. `test2`: Uses a regular expression (`regex`) to match the ISO string and replace it with a new format "month-day-year". The replacement string is hardcoded as `$<month>-$<day>-$<year>`, which suggests that the intent is to extract the month, day, and year parts from the original string. 3. `test3`: Splits the first 10 characters of the ISO string, takes a subset of those characters (specifically, the last three), appends a hyphen, and then appends the first 4 characters followed by another hyphen. **Individual Test Cases** Each test case corresponds to one of the benchmark functions defined in the `Script Preparation Code`. The test cases are: 1. `split and join`: Tests `test1` function. 2. `readable regex`: Tests `test2` function. 3. `slice and append mess`: Tests `test3` function. **Library Usage** The benchmark uses JavaScript's built-in `Date` object to create the date strings in ISO format, which is then passed to each test function. No external libraries are explicitly mentioned in the `Script Preparation Code`. However, it's worth noting that the regular expression used in `test2` (`regex`) might be optimized for performance or efficiency, but its usage doesn't require any additional library. **Special JS Feature/Syntax** The benchmark uses JavaScript's built-in `Date` object and string manipulation methods (e.g., `split`, `join`, `replace`). The regular expression used in `test2` (`regex`) is also a standard JavaScript feature. No special or experimental JavaScript features are being tested here. **Alternatives** For comparing the performance of different approaches to date manipulation, you might consider alternatives like: 1. Using a library like Moment.js for date manipulation. 2. Implementing custom date parsing and formatting logic using bitwise operations or other low-level techniques. 3. Utilizing web workers or parallel processing to compare the performance of each test function on separate threads. However, keep in mind that these alternatives might introduce additional overhead, complexity, or dependencies, which could affect the accuracy or practicality of the benchmark results. I hope this explanation helps!
Related benchmarks:
toISOString vs concat
String split date vs parse date
String split date vs parse date 2
String split date vs parse date 3
Comments
Confirm delete:
Do you really want to delete benchmark?