@contrail/util 1.1.14-alpha → 1.1.14-alpha-1
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.
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
type PerformanceComparisonEvent = {
|
|
2
|
+
durationMsJson: number;
|
|
3
|
+
durationMsRFDC: number;
|
|
4
|
+
input: any;
|
|
5
|
+
};
|
|
6
|
+
type PerformanceSummary = {
|
|
7
|
+
eventForWhichJsonWasMostFaster: PerformanceComparisonEvent | null;
|
|
8
|
+
eventForWhichRFDCWasMostFaster: PerformanceComparisonEvent | null;
|
|
9
|
+
totalDurationMsJson: number;
|
|
10
|
+
totalDurationMsRFDC: number;
|
|
11
|
+
invocationsInWhichJsonWasFaster: PerformanceComparisonEvent[];
|
|
12
|
+
invocationsInWhichRFDCWasFaster: PerformanceComparisonEvent[];
|
|
13
|
+
};
|
|
14
|
+
declare global {
|
|
15
|
+
interface Window {
|
|
16
|
+
performanceSummary: PerformanceSummary;
|
|
17
|
+
performanceEvents: PerformanceComparisonEvent[];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
1
20
|
export declare function cloneDeep<T>(obj: T, options?: {
|
|
2
21
|
shouldPreserveCircularReferences?: boolean;
|
|
3
22
|
}): T;
|
|
23
|
+
export {};
|
|
@@ -5,7 +5,49 @@ const cloneDefault = require('rfdc')();
|
|
|
5
5
|
const cloneWithCircles = require('rfdc')({ circles: true });
|
|
6
6
|
function cloneDeep(obj, options) {
|
|
7
7
|
var _a;
|
|
8
|
+
console.log('running cloneDeep');
|
|
8
9
|
const shouldPreserveCircles = (_a = options === null || options === void 0 ? void 0 : options.shouldPreserveCircularReferences) !== null && _a !== void 0 ? _a : false;
|
|
9
10
|
const clone = shouldPreserveCircles ? cloneWithCircles : cloneDefault;
|
|
10
|
-
|
|
11
|
+
const startJson = performance.now();
|
|
12
|
+
JSON.parse(JSON.stringify(obj));
|
|
13
|
+
const durationMsJson = performance.now() - startJson;
|
|
14
|
+
const startRFDC = performance.now();
|
|
15
|
+
const rfdcClone = clone(obj);
|
|
16
|
+
const durationMsRFDC = performance.now() - startRFDC;
|
|
17
|
+
if (!window.performanceEvents) {
|
|
18
|
+
window.performanceEvents = [];
|
|
19
|
+
}
|
|
20
|
+
const performanceEvent = {
|
|
21
|
+
durationMsJson,
|
|
22
|
+
durationMsRFDC,
|
|
23
|
+
input: obj,
|
|
24
|
+
};
|
|
25
|
+
window.performanceEvents.push(performanceEvent);
|
|
26
|
+
window.performanceSummary = window.performanceSummary || {
|
|
27
|
+
eventForWhichJsonWasMostFaster: null,
|
|
28
|
+
eventForWhichRFDCWasMostFaster: null,
|
|
29
|
+
totalDurationMsJson: 0,
|
|
30
|
+
totalDurationMsRFDC: 0,
|
|
31
|
+
invocationsInWhichJsonWasFaster: [],
|
|
32
|
+
invocationsInWhichRFDCWasFaster: [],
|
|
33
|
+
};
|
|
34
|
+
window.performanceSummary.totalDurationMsJson += durationMsJson;
|
|
35
|
+
window.performanceSummary.totalDurationMsRFDC += durationMsRFDC;
|
|
36
|
+
const isJsonFaster = durationMsJson < durationMsRFDC;
|
|
37
|
+
if (isJsonFaster) {
|
|
38
|
+
window.performanceSummary.invocationsInWhichJsonWasFaster.push(performanceEvent);
|
|
39
|
+
if (!window.performanceSummary.eventForWhichJsonWasMostFaster ||
|
|
40
|
+
durationMsJson < window.performanceSummary.eventForWhichJsonWasMostFaster.durationMsJson) {
|
|
41
|
+
window.performanceSummary.eventForWhichJsonWasMostFaster = performanceEvent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
window.performanceSummary.invocationsInWhichRFDCWasFaster.push(performanceEvent);
|
|
46
|
+
if (!window.performanceSummary.eventForWhichRFDCWasMostFaster ||
|
|
47
|
+
durationMsRFDC < window.performanceSummary.eventForWhichRFDCWasMostFaster.durationMsRFDC) {
|
|
48
|
+
window.performanceSummary.eventForWhichRFDCWasMostFaster = performanceEvent;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
console.log('cloneDeep performance summary:', window.performanceSummary);
|
|
52
|
+
return rfdcClone;
|
|
11
53
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const lodash_1 = require("lodash");
|
|
4
|
+
const cloneDeep_1 = require("./cloneDeep");
|
|
5
|
+
function jsonClone(obj) {
|
|
6
|
+
return JSON.parse(JSON.stringify(obj));
|
|
7
|
+
}
|
|
8
|
+
console.log('Performance test for very large objects:');
|
|
9
|
+
let veryLargeObject = {};
|
|
10
|
+
for (let i = 0; i < 100000; i++) {
|
|
11
|
+
veryLargeObject[`key${i}`] = {
|
|
12
|
+
sub1: {
|
|
13
|
+
val: i,
|
|
14
|
+
},
|
|
15
|
+
sub2: new Date('2023-10-01T12:00:00.000Z'),
|
|
16
|
+
sub3: {
|
|
17
|
+
val: i + 1,
|
|
18
|
+
valX: i + 2,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
console.time('cloneDeep');
|
|
23
|
+
(0, cloneDeep_1.cloneDeep)(veryLargeObject);
|
|
24
|
+
console.timeEnd('cloneDeep');
|
|
25
|
+
console.time('cloneDeepLodash');
|
|
26
|
+
(0, lodash_1.cloneDeep)(veryLargeObject);
|
|
27
|
+
console.timeEnd('cloneDeepLodash');
|
|
28
|
+
console.time('cloneDeepJson');
|
|
29
|
+
jsonClone(veryLargeObject);
|
|
30
|
+
console.timeEnd('cloneDeepJson');
|
|
31
|
+
console.time('structuredClone');
|
|
32
|
+
structuredClone(veryLargeObject);
|
|
33
|
+
console.timeEnd('structuredClone');
|
|
34
|
+
console.log('\n\nPerformance test for very large arrays:');
|
|
35
|
+
let veryLargeArray = [];
|
|
36
|
+
for (let i = 0; i < 100000; i++) {
|
|
37
|
+
veryLargeArray.push({
|
|
38
|
+
sub1: {
|
|
39
|
+
val: i,
|
|
40
|
+
},
|
|
41
|
+
sub2: new Date('2023-10-01T12:00:00.000Z'),
|
|
42
|
+
sub3: {
|
|
43
|
+
val: i + 1,
|
|
44
|
+
valX: i + 2,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
console.time('cloneDeepArray');
|
|
49
|
+
(0, cloneDeep_1.cloneDeep)(veryLargeArray);
|
|
50
|
+
console.timeEnd('cloneDeepArray');
|
|
51
|
+
console.time('cloneDeepArrayLodash');
|
|
52
|
+
(0, lodash_1.cloneDeep)(veryLargeArray);
|
|
53
|
+
console.timeEnd('cloneDeepArrayLodash');
|
|
54
|
+
console.time('cloneDeepArrayJson');
|
|
55
|
+
jsonClone(veryLargeArray);
|
|
56
|
+
console.timeEnd('cloneDeepArrayJson');
|
|
57
|
+
console.time('structuredCloneArray');
|
|
58
|
+
structuredClone(veryLargeArray);
|
|
59
|
+
console.timeEnd('structuredCloneArray');
|
|
60
|
+
console.log('\n\nPerformance test for assortment.json:');
|
|
61
|
+
const fs = require("fs");
|
|
62
|
+
const path = require("path");
|
|
63
|
+
const assortmentFilePath = path.join(__dirname, 'assortment.json');
|
|
64
|
+
const assortmentData = JSON.parse(fs.readFileSync(assortmentFilePath, 'utf8'));
|
|
65
|
+
console.time('cloneDeepAssortment25k');
|
|
66
|
+
(0, cloneDeep_1.cloneDeep)(assortmentData);
|
|
67
|
+
console.timeEnd('cloneDeepAssortment25k');
|
|
68
|
+
console.time('cloneDeepAssortment25kLodash');
|
|
69
|
+
(0, lodash_1.cloneDeep)(assortmentData);
|
|
70
|
+
console.timeEnd('cloneDeepAssortment25kLodash');
|
|
71
|
+
console.time('cloneDeepAssortment25kJson');
|
|
72
|
+
jsonClone(assortmentData);
|
|
73
|
+
console.timeEnd('cloneDeepAssortment25kJson');
|
|
74
|
+
console.time('structuredCloneAssortment25k');
|
|
75
|
+
structuredClone(assortmentData);
|
|
76
|
+
console.timeEnd('structuredCloneAssortment25k');
|