@contrail/util 1.1.14-alpha-1 → 1.1.14-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,10 +11,19 @@ type PerformanceSummary = {
|
|
|
11
11
|
invocationsInWhichJsonWasFaster: PerformanceComparisonEvent[];
|
|
12
12
|
invocationsInWhichRFDCWasFaster: PerformanceComparisonEvent[];
|
|
13
13
|
};
|
|
14
|
+
type CloneMethods = {
|
|
15
|
+
cloneRfdc: <T>(obj: T) => T;
|
|
16
|
+
cloneJson: <T>(obj: T) => T;
|
|
17
|
+
withTiming: (fn: () => any) => {
|
|
18
|
+
result: any;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
14
22
|
declare global {
|
|
15
23
|
interface Window {
|
|
16
24
|
performanceSummary: PerformanceSummary;
|
|
17
25
|
performanceEvents: PerformanceComparisonEvent[];
|
|
26
|
+
cloneMethods: CloneMethods;
|
|
18
27
|
}
|
|
19
28
|
}
|
|
20
29
|
export declare function cloneDeep<T>(obj: T, options?: {
|
|
@@ -3,17 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.cloneDeep = cloneDeep;
|
|
4
4
|
const cloneDefault = require('rfdc')();
|
|
5
5
|
const cloneWithCircles = require('rfdc')({ circles: true });
|
|
6
|
+
function cloneRfdc(obj, options) {
|
|
7
|
+
var _a;
|
|
8
|
+
const shouldPreserveCircles = (_a = options === null || options === void 0 ? void 0 : options.shouldPreserveCircularReferences) !== null && _a !== void 0 ? _a : false;
|
|
9
|
+
const clone = shouldPreserveCircles ? cloneWithCircles : cloneDefault;
|
|
10
|
+
return clone(obj);
|
|
11
|
+
}
|
|
12
|
+
function withTiming(fn) {
|
|
13
|
+
const start = performance.now();
|
|
14
|
+
const result = fn();
|
|
15
|
+
const durationMs = performance.now() - start;
|
|
16
|
+
return { result, durationMs };
|
|
17
|
+
}
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
var window = {};
|
|
20
|
+
}
|
|
21
|
+
window.cloneMethods = {
|
|
22
|
+
cloneRfdc,
|
|
23
|
+
cloneJson: (obj) => JSON.parse(JSON.stringify(obj)),
|
|
24
|
+
withTiming,
|
|
25
|
+
};
|
|
6
26
|
function cloneDeep(obj, options) {
|
|
7
27
|
var _a;
|
|
8
|
-
console.log('running cloneDeep');
|
|
9
28
|
const shouldPreserveCircles = (_a = options === null || options === void 0 ? void 0 : options.shouldPreserveCircularReferences) !== null && _a !== void 0 ? _a : false;
|
|
10
29
|
const clone = shouldPreserveCircles ? cloneWithCircles : cloneDefault;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const durationMsJson = performance.now() - startJson;
|
|
14
|
-
const startRFDC = performance.now();
|
|
30
|
+
const { durationMs: durationMsJson } = withTiming(() => JSON.parse(JSON.stringify(obj)));
|
|
31
|
+
const { durationMs: durationMsRFDC } = withTiming(() => clone(obj));
|
|
15
32
|
const rfdcClone = clone(obj);
|
|
16
|
-
const durationMsRFDC = performance.now() - startRFDC;
|
|
17
33
|
if (!window.performanceEvents) {
|
|
18
34
|
window.performanceEvents = [];
|
|
19
35
|
}
|
|
@@ -48,6 +64,5 @@ function cloneDeep(obj, options) {
|
|
|
48
64
|
window.performanceSummary.eventForWhichRFDCWasMostFaster = performanceEvent;
|
|
49
65
|
}
|
|
50
66
|
}
|
|
51
|
-
console.log('cloneDeep performance summary:', window.performanceSummary);
|
|
52
67
|
return rfdcClone;
|
|
53
68
|
}
|
|
@@ -5,7 +5,37 @@ const cloneDeep_1 = require("./cloneDeep");
|
|
|
5
5
|
function jsonClone(obj) {
|
|
6
6
|
return JSON.parse(JSON.stringify(obj));
|
|
7
7
|
}
|
|
8
|
-
console.log('Performance test for
|
|
8
|
+
console.log('Performance test for small objects:');
|
|
9
|
+
let smallObject = {
|
|
10
|
+
sub1: {
|
|
11
|
+
val: 1,
|
|
12
|
+
},
|
|
13
|
+
sub3: {
|
|
14
|
+
val: 2,
|
|
15
|
+
valX: '3',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
console.time('cloneDeepSmallRFDC');
|
|
19
|
+
Array.from({ length: 10000 }).forEach(() => {
|
|
20
|
+
(0, cloneDeep_1.cloneDeep)(smallObject);
|
|
21
|
+
});
|
|
22
|
+
console.timeEnd('cloneDeepSmallRFDC');
|
|
23
|
+
console.time('cloneDeepSmallLodash');
|
|
24
|
+
Array.from({ length: 10000 }).forEach(() => {
|
|
25
|
+
(0, lodash_1.cloneDeep)(smallObject);
|
|
26
|
+
});
|
|
27
|
+
console.timeEnd('cloneDeepSmallLodash');
|
|
28
|
+
console.time('cloneDeepSmallJson');
|
|
29
|
+
Array.from({ length: 10000 }).forEach(() => {
|
|
30
|
+
jsonClone(smallObject);
|
|
31
|
+
});
|
|
32
|
+
console.timeEnd('cloneDeepSmallJson');
|
|
33
|
+
console.time('structuredCloneSmall');
|
|
34
|
+
Array.from({ length: 10000 }).forEach(() => {
|
|
35
|
+
structuredClone(smallObject);
|
|
36
|
+
});
|
|
37
|
+
console.timeEnd('structuredCloneSmall');
|
|
38
|
+
console.log('\n\nPerformance test for very large objects:');
|
|
9
39
|
let veryLargeObject = {};
|
|
10
40
|
for (let i = 0; i < 100000; i++) {
|
|
11
41
|
veryLargeObject[`key${i}`] = {
|
|
@@ -19,9 +49,9 @@ for (let i = 0; i < 100000; i++) {
|
|
|
19
49
|
},
|
|
20
50
|
};
|
|
21
51
|
}
|
|
22
|
-
console.time('
|
|
52
|
+
console.time('cloneDeepRFDC');
|
|
23
53
|
(0, cloneDeep_1.cloneDeep)(veryLargeObject);
|
|
24
|
-
console.timeEnd('
|
|
54
|
+
console.timeEnd('cloneDeepRFDC');
|
|
25
55
|
console.time('cloneDeepLodash');
|
|
26
56
|
(0, lodash_1.cloneDeep)(veryLargeObject);
|
|
27
57
|
console.timeEnd('cloneDeepLodash');
|
|
@@ -45,9 +75,9 @@ for (let i = 0; i < 100000; i++) {
|
|
|
45
75
|
},
|
|
46
76
|
});
|
|
47
77
|
}
|
|
48
|
-
console.time('
|
|
78
|
+
console.time('cloneDeepArrayRFDC');
|
|
49
79
|
(0, cloneDeep_1.cloneDeep)(veryLargeArray);
|
|
50
|
-
console.timeEnd('
|
|
80
|
+
console.timeEnd('cloneDeepArrayRFDC');
|
|
51
81
|
console.time('cloneDeepArrayLodash');
|
|
52
82
|
(0, lodash_1.cloneDeep)(veryLargeArray);
|
|
53
83
|
console.timeEnd('cloneDeepArrayLodash');
|
|
@@ -62,9 +92,9 @@ const fs = require("fs");
|
|
|
62
92
|
const path = require("path");
|
|
63
93
|
const assortmentFilePath = path.join(__dirname, 'assortment.json');
|
|
64
94
|
const assortmentData = JSON.parse(fs.readFileSync(assortmentFilePath, 'utf8'));
|
|
65
|
-
console.time('
|
|
95
|
+
console.time('cloneDeepAssortment25kRFDC');
|
|
66
96
|
(0, cloneDeep_1.cloneDeep)(assortmentData);
|
|
67
|
-
console.timeEnd('
|
|
97
|
+
console.timeEnd('cloneDeepAssortment25kRFDC');
|
|
68
98
|
console.time('cloneDeepAssortment25kLodash');
|
|
69
99
|
(0, lodash_1.cloneDeep)(assortmentData);
|
|
70
100
|
console.timeEnd('cloneDeepAssortment25kLodash');
|