소스 검색

Added heap usage performance test

sanex3339 5 년 전
부모
커밋
b1bb4a91af
3개의 변경된 파일58개의 추가작업 그리고 0개의 파일을 삭제
  1. 0 0
      dist/index.cli.js
  2. 0 0
      dist/index.js
  3. 58 0
      test/performance-tests/JavaScriptObfuscatorPerformance.spec.ts

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/index.cli.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/index.js


+ 58 - 0
test/performance-tests/JavaScriptObfuscatorPerformance.spec.ts

@@ -4,6 +4,8 @@ import { readFileAsString } from '../helpers/readFileAsString';
 
 import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscatorFacade';
 
+const heapValueToMB = (value: number) => Math.round(value / 1024 / 1024 * 100) / 100;
+
 describe('JavaScriptObfuscator performance', function () {
     const iterationsCount: number = 500;
 
@@ -26,4 +28,60 @@ describe('JavaScriptObfuscator performance', function () {
             assert.isOk(true);
         });
     });
+
+    describe('performance: heap usage', () => {
+        it('should keep heap usage without memory leakd', () => {
+            const sourceCode: string = readFileAsString('./test/fixtures/sample.js');
+
+            const maxHeapUsed: number[] = [];
+            let prevHeapUsed: number | null = null;
+
+            for (let i: number = 0; i < iterationsCount; i++) {
+                JavaScriptObfuscator.obfuscate(
+                    sourceCode,
+                    {
+                        compact: true,
+                        controlFlowFlattening: true,
+                        controlFlowFlatteningThreshold: 0.75,
+                        deadCodeInjection: true,
+                        deadCodeInjectionThreshold: 0.4,
+                        debugProtection: false,
+                        debugProtectionInterval: false,
+                        disableConsoleOutput: true,
+                        identifierNamesGenerator: 'mangled',
+                        log: false,
+                        renameGlobals: false,
+                        rotateStringArray: true,
+                        selfDefending: true,
+                        shuffleStringArray: true,
+                        splitStrings: true,
+                        splitStringsChunkLength: 2,
+                        stringArray: true,
+                        stringArrayEncoding: 'base64',
+                        stringArrayThreshold: 0.75,
+                        transformObjectKeys: true,
+                        unicodeEscapeSequence: false
+                    }
+                );
+
+                const used = process.memoryUsage();
+                const heapUsed: number = heapValueToMB(used.heapUsed);
+
+                if (prevHeapUsed !== null && heapUsed < prevHeapUsed) {
+                    maxHeapUsed.push(prevHeapUsed);
+                }
+
+                prevHeapUsed = heapUsed;
+            }
+
+            const sortedMaxHeapUsed: number[] = [...maxHeapUsed].sort();
+
+            const firstMaxHeapMBUsed: number = sortedMaxHeapUsed[0];
+            const lastMaxHeapMbUsed: number = sortedMaxHeapUsed[sortedMaxHeapUsed.length - 1];
+
+            const diff: number = lastMaxHeapMbUsed - firstMaxHeapMBUsed;
+
+            assert.closeTo(diff, 0, 20);
+        });
+    });
 });

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.