Skip to content

Commit 83c8a82

Browse files
committed
Add new test cases
1 parent 9ed8102 commit 83c8a82

File tree

5 files changed

+70
-9
lines changed

5 files changed

+70
-9
lines changed

JavaScript/2-benchmark.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ benchmark.do = (count, retry, tests) => {
99
for (k = 0; k < retry; k++) {
1010
tests.map(test);
1111
console.log();
12+
if (global.gc) gc();
1213
}
1314

1415
function test(fn) {

JavaScript/3-instantiation.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
const benchmark = require('./2-benchmark.js');
44

5-
benchmark.do(10000000, 3, [
5+
benchmark.do(10000000, 5, [
66
defineObject,
77
defineArray,
8+
defineArrayOfString,
9+
defineArrayOfNumber,
810
mixinObject,
911
newInstance,
1012
newObject,
@@ -20,6 +22,23 @@ function defineArray() {
2022
];
2123
}
2224

25+
function defineArrayOfString() {
26+
return [
27+
'world',
28+
'world',
29+
'world'
30+
];
31+
}
32+
33+
function defineArrayOfNumber() {
34+
return [
35+
100500,
36+
100500,
37+
100500
38+
];
39+
}
40+
41+
2342
function defineObject() {
2443
return {
2544
hello: 'world',

JavaScript/6-functions.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,39 @@
22

33
const benchmark = require('./2-benchmark.js');
44

5-
const fnLambda = () => {};
5+
const fnLambdaBlock = () => {};
6+
const fnLambdaBlockU = () => { return; };
7+
const fnLambdaBlockN = () => { return null; };
8+
const fnLambdaBlock0 = () => { return 0; };
69

7-
const fnExpression = function() {
8-
};
10+
const fnLambdaExprU = () => undefined;
11+
const fnLambdaExprN = () => null;
12+
const fnLambdaExpr0 = () => 0;
913

10-
function fnDeclaration() {
11-
}
14+
const fnExpression = function() {};
15+
const fnExpressionU = function() { return; };
16+
const fnExpressionN = function() { return null; };
17+
const fnExpression0 = function() { return 0; };
1218

13-
benchmark.do(10000000, 5, [
19+
function fnDeclaration() {}
20+
function fnDeclarationU() { return; }
21+
function fnDeclarationN() { return null; }
22+
function fnDeclaration0() { return 0; }
23+
24+
benchmark.do(100000000, 3, [
25+
fnLambdaBlock,
26+
fnLambdaBlockU,
27+
fnLambdaBlockN,
28+
fnLambdaBlock0,
29+
fnLambdaExprU,
30+
fnLambdaExprN,
31+
fnLambdaExpr0,
1432
fnDeclaration,
33+
fnDeclarationU,
34+
fnDeclarationN,
35+
fnDeclaration0,
1536
fnExpression,
16-
fnLambda,
37+
fnExpressionU,
38+
fnExpressionN,
39+
fnExpression0
1740
]);

JavaScript/a-tick-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function testConcat() {
77
}
88

99
function testTick() {
10-
return `Hello user${parseInt('5') * 10}!`;
10+
return `Hello user${parseInt('5') * 10} !`;
1111
}
1212

1313
benchmark.do(10000000, 5, [

JavaScript/b-es6-map.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ cities.set('Beijing', { name: 'Пекин', population: 11510000 });
1010
cities.set('Kiev', { name: 'Киев', population: 2804000 });
1111
cities.set('Riga', { name: 'Рига', population: 643615 });
1212

13+
const citiesOld = {
14+
Athens: { name: 'Афины', population: 664046 },
15+
Rome: { name: 'Рим', population: 2627000 },
16+
London: { name: 'Лондон', population: 8674000 },
17+
Beijing: { name: 'Пекин', population: 11510000 },
18+
Kiev: { name: 'Киев', population: 2804000 },
19+
Riga: { name: 'Рига', population: 643615 }
20+
};
21+
22+
function testForInHash() {
23+
const arr = [];
24+
let key;
25+
for (key in citiesOld) {
26+
arr.push([ citiesOld[key], key ]);
27+
}
28+
}
29+
1330
function testForEach() {
1431
const arr = [];
1532
cities.forEach((value, key) => {
@@ -46,6 +63,7 @@ function testForOfEntries() {
4663
}
4764

4865
benchmark.do(1000000, 4, [
66+
testForInHash,
4967
testForEach,
5068
testForOf,
5169
testForOfKeys,

0 commit comments

Comments
 (0)