<script src="https://cdn.jsdelivr.net/npm/hash-sum@2.0.0/hash-sum.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/object-hash@2.0.3/dist/object_hash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
var context1 = {
title: 'fish',
foo: [{ bar: { baz: true }, arr: [1,2,3,4,5,"pirate"]}],
position: 1
}
var context2 = {
title: 'fish',
foo: [{ bar: { baz: true }, arr: [1,2,3,4,5,"pirate"]}],
position: 1
}
sum(context1) === sum(context2)
objectHash(context1) === objectHash(context2)
_.isEqual(context1, context2)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Sum | |
Object-hash | |
isEqual |
Test name | Executions per second |
---|---|
Sum | 87542.3 Ops/sec |
Object-hash | 8329.5 Ops/sec |
isEqual | 1099404.5 Ops/sec |
Let's break down the benchmark and its test cases.
Benchmark Purpose
MeasureThat.net is used to compare the performance of different algorithms for calculating hashes or equality checks on JavaScript objects. The goal is to determine which approach is faster in various scenarios.
Script Preparation Code
The script preparation code defines two JavaScript objects, context1
and context2
, with similar properties and values. The main difference between the two objects is that context1
has a nested object bar
with an array property arr
, while context2
does not have this nested structure.
Html Preparation Code
The HTML preparation code includes three external JavaScript libraries:
hash-sum
: a library for calculating hashes on strings.object-hash
: a library for calculating hashes on objects.lodash
: a utility library that provides various functions, including isEqual
, which is used in the benchmark.Test Cases
There are three test cases:
sum()
on context1
and context2
. The sum()
function likely calculates the sum of all elements in an array.objectHash()
on context1
and context2
._.isEqual()
on context1
and context2
. The _
refers to the Lodash library.Options Compared
The three test cases compare different approaches for calculating hashes or equality checks:
Pros and Cons
Here are some pros and cons of each approach:
Other Considerations
When choosing an approach, consider the following factors:
Alternatives
If you need to perform hash calculations or equality checks on JavaScript objects, here are some alternative approaches:
Keep in mind that each approach has its own strengths and weaknesses, and the choice ultimately depends on your specific use case and requirements.