<script src="
https://cdn.jsdelivr.net/npm/object-hash@3.0.0/dist/object_hash.min.js
"></script>
window.data = {
prop1: {
a: 1,
b: 'a'
},
prop2: {
a: 1,
b: 'a'
},
prop3: {
a: 1,
b: 'a'
},
prop4: {
a: 1,
b: 'a'
},
prop5: {
a: 1,
b: 'a'
},
};
objectHash(window.data);
JSON.stringify(window.data);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object hash | |
JSON.stringify |
Test name | Executions per second |
---|---|
Object hash | 13099.5 Ops/sec |
JSON.stringify | 3690302.8 Ops/sec |
Let's break down the benchmark and its components.
Benchmark Definition
The benchmark consists of two individual test cases:
objectHash
function from the object-hash
library, passing in the window.data
object as an argument.JSON.stringify
function, also passing in the window.data
object as an argument.Options Compared
The two options being compared are:
object-hash
)Stringify
method of JavaScript's native JSON API (JSON.stringify
)Pros and Cons
Pros:
object-hash
library is optimized for speed, making it suitable for high-performance use cases.Cons:
Pros:
JSON.stringify
method is a built-in part of JavaScript's native API, eliminating the need for external dependencies.Cons:
JSON.stringify
method may not be as optimized or efficient as a dedicated hashing library like object-hash
.Library Description
The object-hash
library is a lightweight, purpose-built JavaScript library designed specifically for hashing objects. Its primary purpose is to provide fast and efficient object hashing capabilities, making it suitable for applications requiring high-performance data integrity checks or encryption.
Special JS Features/Syntax
In this benchmark, the following special JavaScript features are used:
window.data
object is defined in a separate script preparation code block.objectHash
function from the object-hash
library is called to perform the hashing operation.JSON.stringify
method is used to create a JSON string representation of the input data.These features and syntax are not specific to this benchmark, but rather common practices in JavaScript development.