<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var data = Array(1000000).fill('a');
_.join(data, ',')
data.join(',')
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
lodash | |
native |
Test name | Executions per second |
---|---|
lodash | 42.7 Ops/sec |
native | 42.3 Ops/sec |
Let's dive into the world of microbenchmarks on MeasureThat.net.
Benchmark Definition and Script Preparation Code
The benchmark definition is a JSON object that describes a specific JavaScript operation to be performed: joining an array of strings using a comma separator. The script preparation code creates a large array data
filled with 1 million 'a' characters, which will be used for the join operation.
Html Preparation Code
The HTML preparation code includes a script tag that loads the Lodash library version 4.17.5 from a CDN. This library is used to implement the join operation in the benchmark definition.
Test Cases and Libraries Used
There are two test cases:
_.join()
function from the Lodash library to perform the join operation.Array.join()
without any additional libraries or helpers.Options Compared and Their Pros/Cons
The main difference between these two approaches is how they handle string concatenation:
_.join()
)Array.join()
)Array.join()
is not immediately clear.Special JS Feature or Syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on comparing two different approaches to a simple string join operation.
Alternatives
Other alternatives for implementing string joins could include:
String.prototype.join()
method directly on the array, like so: data.join(',')
Array.prototype.forEach()
and concatenationSpread Operator
(...
) for more concise codeHowever, in this specific benchmark, the focus is on comparing the performance of Lodash's join functionality with native implementation.