-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.js
More file actions
82 lines (76 loc) · 2.18 KB
/
benchmark.js
File metadata and controls
82 lines (76 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Bench, hrtimeNow } from "tinybench";
import mdiff from "microdiff";
import { diff } from "./packages/obj-diff/dist/index";
import { detailedDiff } from "deep-object-diff";
import { diff as justDiff } from "just-diff";
import deepDiff from "deep-diff";
const obj1 = {
id: 8,
title: "Microsoft Surface Laptop 4",
description: "Style and speed. Stand out on ...",
price: 1499,
discountPercentage: 10.23,
rating: 4.43,
stock: { inStock: true, count: 68 },
brand: "Microsoft Surface",
category: "laptops",
resources: {
images: {
thumbnail: "https://cdn.dummyjson.com/product-images/8/thumbnail.jpg",
items: [
"https://cdn.dummyjson.com/product-images/8/1.jpg",
"https://cdn.dummyjson.com/product-images/8/2.jpg",
"https://cdn.dummyjson.com/product-images/8/3.jpg",
"https://cdn.dummyjson.com/product-images/8/4.jpg",
"https://cdn.dummyjson.com/product-images/8/thumbnail.jpg",
],
},
},
createdAt: new Date("2024-01-01"),
updatedAt: new Date("2024-01-02"),
extraProp: null
};
const obj2 = {
id: 8,
title: "Microsoft Surface Laptop 4",
description: "Style and speed. Stand out on.",
price: 1599,
discountPercentage: 10.23,
rating: 4.43,
stock: { inStock: true, count: 18 },
brand: "Microsoft Surface",
category: "laptops",
resources: {
images: {
thumbnail: "https://cdn.dummyjson.com/product-images/8/thumbnail.jpg",
items: [
"https://cdn.dummyjson.com/product-images/8/1.jpg",
"https://cdn.dummyjson.com/product-images/8/2.jpg",
"https://cdn.dummyjson.com/product-images/8/3.jpg",
"https://cdn.dummyjson.com/product-images/8/4.jpg",
],
},
},
createdAt: new Date("2024-01-01"),
updatedAt: new Date("2024-01-03"),
};
const bench = new Bench({ time: 100, now: hrtimeNow });
bench
.add("diff", () => {
diff(obj1, obj2);
})
.add("microdiff", () => {
mdiff(obj1, obj2);
})
.add("deep-object-diff", () => {
detailedDiff(obj1, obj2);
})
.add("just-diff", () => {
justDiff(obj1, obj2);
})
.add("deep-diff", () => {
deepDiff(obj1, obj2);
});
await bench.warmup();
await bench.run();
console.table(bench.table());