Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
isString Test
(version: 0)
Comparing performance of:
lodash vs replacement
Created:
5 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 Preparation code:
function isString(input) { if (input === '') return true; if (input && typeof input.valueOf() === 'string') { return true; } return false; } var emptyString = ''; var nullString = null; var normalString = 'hello'; var array = ['hello']; var otherObject = {}; var objectString = new String('hello');
Tests:
lodash
for (let i = 0; i < 1000; i++) { _.isString(emptyString); _.isString(nullString); _.isString(normalString); _.isString(array); _.isString(otherObject); _.isString(objectString); }
replacement
for (let i = 0; i < 1000; i++) { isString(emptyString); isString(nullString); isString(normalString); isString(array); isString(otherObject); isString(objectString); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
replacement
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
12070.0 Ops/sec
replacement
43333.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested. **Benchmark Definition** The benchmark is called "isString Test" and has two test cases: "lodash" and "replacement". The script preparation code defines a function `isString` that takes an input and returns a boolean indicating whether it's a string. The function uses a few special variables: * `emptyString`: an empty string * `nullString`: a null value (not a string) * `normalString`: a string containing the text "hello" * `array`: an array containing a single string element ("hello") * `otherObject`: an object (not a string) * `objectString`: a string created using the String constructor The HTML preparation code loads the Lodash library from a CDN. **Test Cases** There are two test cases: 1. **Lodash**: This test case uses the Lodash library to call the `isString` function for each of the special variables defined above. The benchmark definition is a JavaScript loop that calls `_isString()` (a method provided by Lodash) 1000 times with each variable as input. 2. **Replacement**: This test case does not use any external libraries and instead uses the plain `isString` function defined in the script preparation code to call itself for each of the special variables, just like in the Lodash test case. **Latest Benchmark Result** The latest benchmark result shows two rows: * For the "replacement" test case (i.e., calling the `isString` function without any library), Chrome 95 can execute the test 1303.593994140625 times per second. * For the "lodash" test case (i.e., using Lodash's `_isString()` method), Chrome 95 can execute the test 817.396240234375 times per second, which is slower than the replacement version. **What's being tested?** The benchmark tests the performance of two approaches to checking if a value is a string: 1. **Lodash**: Using a popular JavaScript library (Lodash) that provides an `isString` method. 2. **Replacement**: Calling a custom `isString` function defined in plain JavaScript. **Pros and Cons:** * Lodash: + Pros: Provides a widely used, well-maintained library with many other utility functions. + Cons: Adds extra overhead due to the library's loading time and method invocation. * Replacement: + Pros: No external dependencies, potentially faster execution due to lower overhead. + Cons: Requires developers to implement custom logic for each utility function they need. **Other Alternatives** Other alternatives for checking if a value is a string in JavaScript include: 1. **Built-in `typeof` operator**: Using the `typeof` operator with the string operand (`"hello".typeof === "string"`). 2. **JavaScript's native `String.prototype.toString()` method**: Calling `toString()` on a value to convert it to a string (e.g., `"hello".toString()`). These alternatives are not explicitly tested in this benchmark, but they might be relevant for other use cases. Hope this explanation helps!
Related benchmarks:
Lodash toString vs String Constructor1
Lodash isString
Lodash toString vs js String Constructor
Lodash isString fork
Lodash toString vs String Constructor 2
Comments
Confirm delete:
Do you really want to delete benchmark?