<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>
var context1 = {
title: 'fish',
position: 1,
array: [1, 2, 3, [4, 5, 6]],
}
var context2 = {
title: 'fish',
position: 1,
array: [1, 2, 3, [4, 5, 6]],
array2: [{}, {}, {}],
}
sum(context1) === sum(context2)
objectHash(context1) === objectHash(context2)
JSON.stringify(context1) === JSON.stringify(context2)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Sum | |
Object-hash | |
JSON.stringify |
Test name | Executions per second |
---|---|
Sum | 124256.6 Ops/sec |
Object-hash | 7164.0 Ops/sec |
JSON.stringify | 2055113.1 Ops/sec |
Benchmark Overview
The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark tests three different approaches to hash or sum complex data structures: hash-sum
, object-hash
, and JSON.stringify
.
Options Compared
sum()
function in the hash-sum
library, which calculates the sum of all elements in an object.objectHash()
function from the object-hash
library, which generates a unique hash for an object based on its properties and values.JSON.stringify()
method.Pros and Cons of Each Approach
hash-sum
due to the hashing algorithm.Library Descriptions
hash-sum
library provides a simple implementation of the sum()
function, which calculates the sum of all elements in an object.object-hash
library generates a unique hash for an object based on its properties and values.Special JS Features or Syntax
The benchmark does not explicitly test any special JavaScript features or syntax.
Benchmark Preparation Code Explanation
The provided preparation code sets up two objects, context1
and context2
, which are used as inputs for the benchmark tests. The code defines these objects in a way that highlights the differences between the three approaches being tested:
context1
has a simple object structure with a single property.context2
has an additional nested array property.Other Alternatives
If you're looking for alternatives to these approaches, consider the following options:
object-hash
.Keep in mind that these alternatives may have different performance characteristics and use cases compared to the approaches tested in this benchmark.