Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
slice substring substr
(version: 0)
Comparing performance of:
1 vs 2 vs 3
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var string = "I am the god of hellfire, and I bring you..."
Tests:
1
string.slice(0, 63);
2
string.substring(0, 63);
3
string.substr(0, 63);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
1
2
3
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
1
123851712.0 Ops/sec
2
129944072.0 Ops/sec
3
132041728.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. The provided JSON represents a benchmark test case that compares the performance of three different methods to extract a substring from a string: `slice`, `substring`, and `substr`. We'll break down each option, their pros and cons, and other considerations. **Methods being compared:** 1. **`string.slice(0, 63)`**: This method is part of the ECMAScript standard and is used to extract a substring from a string. It takes two arguments: the start index and the end index (exclusive). 2. **`string.substring(0, 63)`**: Similar to `slice`, this method is also part of the ECMAScript standard and is used to extract a substring from a string. 3. **`string.substr(0, 63)`**: This method is not part of the ECMAScript standard but is supported by most browsers due to its widespread use in older JavaScript code. **Pros and Cons:** 1. **`slice` and `substring`**: * Pros: + Part of the ECMAScript standard, ensuring consistency across browsers. + Generally faster than `substr`. * Cons: + May have different performance characteristics depending on the browser. 2. **`substr`**: * Pros: + Widely supported in older JavaScript code and by some modern browsers. + Simple to use, with only two arguments (start index and length). * Cons: + Not part of the ECMAScript standard, which may lead to inconsistencies across browsers. + May be slower than `slice` and `substring`. **Other considerations:** * The test case uses a specific string (`"I am the god of hellfire, and I bring you..."`) that is repeated 63 times. This creates a large number of substrings, which can affect performance. * The benchmark results show that Safari 15 performed best in all three test cases, while the other browsers (not mentioned in the provided data) may have different performance characteristics. **Library:** None. **Special JS feature or syntax:** There are no special JavaScript features or syntaxes used in this benchmark. However, it's worth noting that MeasureThat.net supports a wide range of JavaScript features and syntaxes, including ES6+ modules, async/await, and more. **Alternatives:** If you're interested in running similar benchmarks on other platforms, here are some alternatives: 1. **Benchmark.js**: A benchmarking library for Node.js that provides a simple API for creating and running benchmarks. 2. **Benchmarks**: A benchmarking framework for JavaScript that allows you to create custom benchmarks and run them on multiple browsers. 3. **jsperf**: A classic benchmarking website that allows you to compare the performance of different JavaScript code snippets across multiple browsers. Keep in mind that these alternatives may have slightly different APIs and features, so be sure to check their documentation before using them.
Related benchmarks:
Performance Test: substring vs substr vs slice1
Performance Test: substring vs substr vs slice vs split
Performance Test: substring vs substr vs slice 1
Performance Test: substring vs substr vs slice 5
Comments
Confirm delete:
Do you really want to delete benchmark?