Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex split
(version: 0)
regex
Comparing performance of:
regex vs split
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
regex
function test( path, params ) { if (!params) return path const pathParamRegex = /\/:(\w+\(([^)]+)\))\/?/g; return path .replace(pathParamRegex, (_, key) => { console.log(_) console.log(key) if(!params[key[0]]) return "" return params[key[0]] }) .concat(params.queryParams ? makeQueryParams(params.queryParams) : '') } return test('/tet/abc/:c/:param', {c:"test"})
split
const removeStringByStrategy = (strategy) => (target,type, findIndex) => { const strategyFnc = strategy[type]; return strategyFnc(target, findIndex); }; const strategy = { start: (target, findIndex) => target.slice(findIndex + 1, target.length), base: (target, findIndex) => target.slice(0, findIndex) + target.slice(findIndex + 1, target.length), end: (target, findIndex) => target.slice(0, findIndex), }; const removeStringByType = removeStringByStrategy(strategy); /** * type:start - 찾은 문자열을 시작으로 끝 문자열까지 반환(target: "?", value:"react?kim", result="kim") * type:base - 찾은 문자열 하나만 삭제(target: "?", value:"react?kim", result="reactkim") * type:end - 첫번째 위치부터 찾은 문자열 위치에 포함되는 문자열 삭제(target: "?", value:"react?kim", result="asf") * @param target 삭제할 문자열 * @returns {string} */ const remove = (target) => (type) => (value) => { const findIndex = value.indexOf(target); if (findIndex === -1) return value; return removeStringByType(value, type, findIndex); }; const removeBraces = remove("("); // "("가 발견된 지점부터 문자열 끝까지 삭제하는 함수 생성 const removeBracesFromFindIndexToEnd = removeBraces("end"); return'/tet/abc/:c/:param'.split("/").map(removeBracesFromFindIndexToEnd).join("/")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regex
split
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 what's tested in the provided JSON, explain the options compared, and discuss their pros and cons. **Benchmark Definition** The benchmark is defined as "regex split". It's testing the performance of regular expression-based string splitting on different JavaScript engines. **Script Preparation Code** There is no script preparation code provided for this benchmark. This means that the test case is self-contained and doesn't require any external setup or dependencies. **Individual Test Cases** There are two test cases: "regex" and "split". Both test cases are designed to measure the performance of regular expression-based string splitting, but they differ in their implementation: 1. **Test Case 1: Regex** This test case uses a complex regular expression pattern (`/\\/:(\\w+\\(([^)]+)\\))\\/?`) to split a string based on certain conditions. The pattern is designed to match strings that contain a colon followed by a word, an optional group of characters enclosed in parentheses, and another colon. The implementation involves: * Creating a regular expression object using the `pathParamRegex` variable. * Using the `replace()` method to replace matches with a modified version of the original string. * Concatenating query parameters from an input object (`params`) to the resulting string. **Pros:** * This approach tests a more complex and realistic use case for regular expression-based string splitting. * It allows for a comprehensive evaluation of the engine's ability to handle different types of patterns and substitutions. **Cons:** * The test case is highly specific, which might not accurately represent real-world scenarios. * The complexity of the pattern and the number of replacements can lead to performance issues in some engines. 2. **Test Case 2: Split** This test case uses a simpler approach by calling the `split()` method on an array of strings returned by another function (`removeBracesFromFindIndexToEnd`). The `removeBraces` function takes two arguments: the string to be removed and the type of removal (e.g., "end" for removing from the end of the string). The implementation involves: * Creating a `remove` function that takes three arguments: the target string, the type of removal, and the index. * Using this function to create a new version of the original string without certain characters. **Pros:** * This approach is simpler and more straightforward than Test Case 1. * It allows for a more general evaluation of the engine's performance with simple splitting operations. **Cons:** * The test case may not accurately represent real-world scenarios, which often involve more complex logic and edge cases. * The use of a separate `remove` function might introduce unnecessary overhead. **Library Usage** Neither test case uses any external libraries. However, it's worth noting that the `makeQueryParams` function mentioned in Test Case 1 is not defined in the provided code snippet. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in these test cases beyond what's standard in the language.
Related benchmarks:
precompiled regexp vs inline (string split)
String split using regex vs string v3
Very simple regex vs string split
Split vs Regex find
str.match / str.split
Comments
Confirm delete:
Do you really want to delete benchmark?