Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Url sanitize optimization
(version: 1)
Comparing performance of:
old vs new
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/qs/6.7.0/qs.min.js'></script>
Script Preparation code:
var formNames = { queryName: 'qn', sortName: 'sn', recursive: 'rn', }; var values = { sn: 1, youpla: 'toto' }; var url = "qn=Egalite&sn=count%20desc&toto=tata";
Tests:
old
let params = Qs.parse(url); Object.keys(formNames).forEach((key) => { delete params[formNames[key]]; }); _.merge(params, values);
new
const url_params = Qs.parse(url); const to_exclude = _.values(formNames); const params_cleaned = _.omit(url_params, to_exclude); Object.assign(params_cleaned, values);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
old
new
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):
**Benchmark Overview** The provided benchmark, named "Url sanitize optimization", measures the performance of two different approaches to sanitizing URL parameters in JavaScript. The goal is to optimize the removal of unwanted query string parameters from a URL. **Benchmark Definition JSON** The benchmark definition contains three main sections: 1. **Script Preparation Code**: This section provides a JavaScript context with variables and data structures used in the benchmark tests. It defines an object `formNames` that maps parameter names to specific values, as well as another object `values` containing actual query string parameters. 2. **Html Preparation Code**: This section includes links to external libraries: `lodash.js` (version 4.17.5) and `qs.js` (version 6.7.0). These libraries are used in the benchmark tests for string manipulation and URL parsing, respectively. 3. **Benchmark Definition**: The actual benchmark definition is a JSON object that contains two test cases. **Test Cases** The benchmark consists of two individual test cases: 1. **"old"`**: This test case uses `Qs.parse()` to parse the URL and then iterates over the `formNames` object, deleting each parameter from the parsed query string using `delete`. Finally, it merges the cleaned parameters with the `values` object. 2. **"new"`**: This test case also uses `Qs.parse()` to parse the URL. It creates an array of parameters to exclude (`to_exclude`) and then uses `_.omit()` to remove these parameters from the parsed query string. The resulting clean parameters are then merged with the `values` object using `Object.assign()`. **Options Compared** The two test cases compare the performance of different approaches: 1. **"old"`**: Iterates over `formNames` and deletes each parameter individually. 2. **"new"`**: Uses `_.omit()` to remove parameters in a single operation. **Pros and Cons** * **"old"`**: + Pros: Simple, straightforward implementation. + Cons: May be slower due to the iterative deletion process. * **"new"`**: + Pros: More efficient, as it uses a single `_.omit()` function. + Cons: Requires additional library inclusion (`lodash.js`) and may have a slight overhead due to the extra function call. **Library Usage** The benchmark uses two libraries: 1. **`qs.js`**: A URL parsing library that provides an easy-to-use API for extracting query string parameters. 2. **`lodash.js`**: A utility library that includes various functions, including `_.omit()` used in the "new" test case. **Special JS Features or Syntax** There are no special JavaScript features or syntaxes used in this benchmark. The tests rely on standard JavaScript and library-specific APIs provided by `qs.js` and `lodash.js`. **Alternatives** Other alternatives to compare would include: 1. Using a different URL parsing library, such as `url-parameters`. 2. Implementing the sanitization logic using native JavaScript functions (e.g., `String.prototype.split()` and `Array.prototype.filter()`). 3. Using a more complex approach that incorporates multiple libraries or techniques. Keep in mind that these alternatives would likely require significant changes to the benchmark code and may not accurately reflect real-world usage scenarios.
Related benchmarks:
string IndexOf vs string Includes vs lodash includes vs lodash indexOf
_.sortBy vs JS sort
_.sortBy vs _.orderBy vs JS sort
Compount Mapping and Sorting (lodash vs native)
Comments
Confirm delete:
Do you really want to delete benchmark?