8000 Tests against multiple versions. · shelljs/benchmarks@141ff7d · GitHub
[go: up one dir, main page]

Skip to content

Commit 141ff7d

Browse files
committed
Tests against multiple versions.
1 parent 8740340 commit 141ff7d

File tree

26 files changed

+145
-68
lines changed

26 files changed

+145
-68
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "shelljs/latest"]
2+
path = shelljs/latest
3+
url = https://github.com/shelljs/shelljs.git

README.md

Lines changed: 72 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ Woohoo! See below for [ShellJS performance wins](#shelljs-performance-wins).
1313

1414
### ShellJS performance wins
1515

16-
- [echoIntoFile](scripts/echoIntoFile)
17-
- [envVariable](scripts/envVariable)
18-
- [ls10k](scripts/ls10k)
19-
- [touchSyntax06](scripts/touchSyntax06)
16+
- [echoIntoFile](test/echoIntoFile)
17+
- [ls10k](test/ls10k)
18+
- [touchSyntax0.6](test/touchSyntax0.6)
2019

2120
## System Information:
2221

@@ -26,88 +25,119 @@ Woohoo! See below for [ShellJS performance wins](#shelljs-performance-wins).
2625

2726
- x64
2827

29-
- Intel(R) Core(TM) i5-3317U CPU @ 1.70GHz x 4
28+
- Intel(R) Core(TM) i5-3317U CPU @ 1.70GHz × 4
3029

3130
## Node information
3231

33-
- Node.js v5.3.0
32+
- Node.js: v5.3.0
3433

35-
- V8 4.6.85.31
34+
- V8: 4.6.85.31
3635

3736

3837

3938
## Shell Information:
4039

41-
- /bin/bash
40+
- name: `/bin/bash`
4241

43-
44-
- GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)
42+
- version: GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)
4543
Copyright (C) 2013 Free Software Foundation, Inc.
4644
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
4745
This is free software; you are free to change and redistribute it.
4846
There is NO WARRANTY, to the extent permitted by law.
4947

5048

51-
### [echoIntoFile](scripts/echoIntoFile)
49+
### [echoIntoFile](test/echoIntoFile)
50+
51+
- [Bash](test/echoIntoFile/echoIntoFile.sh) took `842` milliseconds
52+
53+
- [ShellJS 0.5.3](test/echoIntoFile/echoIntoFile.js) took `251` milliseconds
54+
55+
- [ShellJS 0.6.0](test/echoIntoFile/echoIntoFile.js) took `260` milliseconds
56+
57+
- [ShellJS latest](test/echoIntoFile/echoIntoFile.js) took `199` milliseconds
58+
59+
ShellJS was `4.231` times faster than Bash
60+
61+
### [envVariable](test/envVariable)
62+
63+
- [Bash](test/envVariable/envVar.sh) took `333` milliseconds
64+
65+
- [ShellJS 0.5.3](test/envVariable/envVar.js) took `288` milliseconds
66+
67+
- [ShellJS 0.6.0](test/envVariable/envVar.js) took `291` milliseconds
68+
69+
- [ShellJS latest](test/envVariable/envVar.js) took `687` milliseconds
70+
71+
Bash was `2.063` times faster than ShellJS
72+
73+
### [forLoopAlternateSyntax](test/forLoopAlternateSyntax)
74+
75+
- [Bash](test/forLoopAlternateSyntax/helloworld10k.sh) took `100` milliseconds
76+
77+
- [ShellJS 0.5.3](test/forLoopAlternateSyntax/helloworld10k.js) took `182` milliseconds
78+
79+
- [ShellJS 0.6.0](test/forLoopAlternateSyntax/helloworld10k.js) took `178` milliseconds
80+
81+
- [ShellJS latest](test/forLoopAlternateSyntax/helloworld10k.js) took `221` milliseconds
5282

53-
- [ShellJS](scripts/echoIntoFile/echoIntoFile.js) took `257` milliseconds
83+
Bash was `2.210` times faster than ShellJS
5484

55-
- [Bash](scripts/echoIntoFile/echoIntoFile.sh) took `832` milliseconds
85+
### [helloworld](test/helloworld)
5686

57-
ShellJS was `3.237` times faster than Bash
87+
- [Bash](test/helloworld/helloworld.sh) took `84` milliseconds
5888

59-
### [envVariable](scripts/envVariable)
89+
- [ShellJS 0.5.3](test/helloworld/helloworld.js) took `161` milliseconds
6090

61-
- [ShellJS](scripts/envVariable/envVar.js) took `1164` milliseconds
91+
- [ShellJS 0.6.0](test/helloworld/helloworld.js) took `170` milliseconds
6292

63-
- [Bash](scripts/envVariable/envVar.sh) took `1451` milliseconds
93+
- [ShellJS latest](test/helloworld/helloworld.js) took `196` milliseconds
6494

65-
ShellJS was `1.247` times faster than Bash
95+
Bash was `2.333` times faster than ShellJS
6696

67-
### [forLoopAlternateSyntax](scripts/forLoopAlternateSyntax)
97+
### [helloworld10k](test/helloworld10k)
6898

69-
- [ShellJS](scripts/forLoopAlternateSyntax/helloworld10k.js) took `184` milliseconds
99+
- [Bash](test/helloworld10k/helloworld10k.sh) took `198` milliseconds
70100

71-
- [Bash](scripts/forLoopAlternateSyntax/helloworld10k.sh) took `92` milliseconds
101+
- [ShellJS 0.5.3](test/helloworld10k/helloworld10k.js) took `300` milliseconds
72102

73-
Bash was `2.000` times faster than ShellJS
103+
- [ShellJS 0.6.0](test/helloworld10k/helloworld10k.js) took `261` milliseconds
74104

75-
### [helloworld](scripts/helloworld)
105+
- [ShellJS latest](test/helloworld10k/helloworld10k.js) took `537` milliseconds
76106

77-
- [ShellJS](scripts/helloworld/helloworld.js) took `178` milliseconds
107+
Bash was `2.712` times faster than ShellJS
78108

79-
- [Bash](scripts/helloworld/helloworld.sh) took `83` milliseconds
109+
### [ls10k](test/ls10k)
80110

81-
Bash was `2.145` times faster than ShellJS
111+
- [Bash](test/ls10k/ls10k.sh) took `13272` milliseconds
82112

83-
### [helloworld10k](scripts/helloworld10k)
113+
- [ShellJS 0.5.3](test/ls10k/ls10k.js) took `1145` milliseconds
84114

85-
- [ShellJS](scripts/helloworld10k/helloworld10k.js) took `288` milliseconds
115+
- [ShellJS 0.6.0](test/ls10k/ls10k.js) took `1313` milliseconds
86116

87-
- [Bash](scripts/helloworld10k/helloworld10k.sh) took `217` milliseconds
117+
- [ShellJS latest](test/ls10k/ls10k.js) took `2348` milliseconds
88118

89-
Bash was `1.327` times faster than ShellJS
119+
ShellJS was `5.652` times faster than Bash
90120

91-
### [ls10k](scripts/ls10k)
121+
### [pwd10k](test/pwd10k)
92122

93-
- [ShellJS](scripts/ls10k/ls10k.js) took `743` milliseconds
123+
- [Bash](test/pwd10k/path10k.sh) took `1259` milliseconds
94124

95-
- [Bash](scripts/ls10k/ls10k.sh) took `10145` milliseconds
125+
- [ShellJS 0.5.3](test/pwd10k/path10k.js) took `1696` milliseconds
96126

97-
ShellJS was `13.654` times faster than Bash
127+
- [ShellJS 0.6.0](test/pwd10k/path10k.js) took `2314` milliseconds
98128

99-
### [pwd10k](scripts/pwd10k)
129+
- [ShellJS latest](test/pwd10k/path10k.js) took `6881` milliseconds
100130

101-
- [ShellJS](scripts/pwd10k/path10k.js) took `2039` milliseconds
131+
Bash was `5.465` times faster than ShellJS
102132

103-
- [Bash](scripts/pwd10k/path10k.sh) took `740` milliseconds
133+
### [touchSyntax0.6](test/touchSyntax0.6)
104134

105-
Bash was `2.755` times faster than ShellJS
135+
- [Bash](test/touchSyntax0.6/touchrm10k.sh) took `1750` milliseconds
106136

107-
### [touchSyntax06](scripts/touchSyntax06)
137+
- Skipping test for ShellJS 0.5.3
108138

109-
- [ShellJS](scripts/touchSyntax06/touchrm10k.js) took `322` milliseconds
139+
- [ShellJS 0.6.0](test/touchSyntax0.6/touchrm10k.js) took `275` milliseconds
110140

111-
- [Bash](scripts/touchSyntax06/touchrm10k.sh) took `1565` milliseconds
141+
- [ShellJS latest](test/touchSyntax0.6/touchrm10k.js) took `523` milliseconds
112142

113-
ShellJS was `4.860` times faster than Bash
143+
ShellJS was `3.346` times faster than Bash

benchmark.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
#!/usr/bin/env node
2-
require('shelljs/global');
2+
require('./shelljs/0.6.0');
33

4-
var TEST_DIR = 'scripts';
4+
var TEST_DIR = 'test';
55

66
var shouldLog = (process.argv[2] === 'log');
77
var log = [];
88

9+
var VERSION_FILE = 'version.txt';
10+
11+
// @returns < 0 if a is an earlier version than b
12+
// > 0 if a is a later version than b
13+
// = 0 if a is an equivalent version to b
14+
function versionCmp(a, b) {
15+
var aParts = a.split('.');
16+
var bParts = b.split('.');
17+
18+
var maxLen = Math.max(aParts.length, bParts.length);
19+
for (var k=0;k<maxLen;k++) {
20+
if (Number(aParts[k]) < Number(bParts[k]))
21+
return -1;
22+
else if (Number(aParts[k]) > Number(bParts[k]))
23+
return 1;
24+
}
25+
return 0;
26+
}
27+
928
function writeLog(msg, link) {
1029
if (!msg)
1130
msg = '';
@@ -46,6 +65,8 @@ function printSystemInfo() {
4665
writeLog(' - version: ' + exec('bash --version', {silent: true}).stdout.replace(/\n+/g, '\n'));
4766
}
4867

68+
var versions = ls(__dirname + '/shelljs/');
69+
4970
cd(__dirname + '/' + TEST_DIR);
5071
var prefix;
5172
var shellJSWins = [];
@@ -75,33 +96,43 @@ ls().forEach(function (dir) {
7596

7697
config.silent = true;
7798

78-
start_time = new Date().getTime();
79-
js_output = exec('node ' + jsfile).stdout;
80-
end_time = new Date().getTime();
81-
js_time = end_time - start_time;
82-
writeLog(' - [ShellJS] took `' + js_time + '` milliseconds', prefix + '/' + jsfile);
83-
8499
start_time = new Date().getTime();
85100
shell_output = exec('bash ' + shfile).stdout;
86101
end_time = new Date().getTime();
87102
shell_time = end_time - start_time;
88103
writeLog(' - [Bash] took `' + shell_time + '` milliseconds', prefix + '/' + shfile);
89104

105+
var minimumVersion = test('-f', VERSION_FILE) ? cat(VERSION_FILE).trim() : '0.0.0';
106+
versions.forEach(function (version) {
107+
if (versionCmp(version, minimumVersion) < 0) {
108+
writeLog(' - Skipping test for ShellJS '+version);
109+
return;
110+
}
111+
var cmd = 'node ' + jsfile + ' ../../shelljs/' +
112+
(version === 'latest' ? 'latest/global' : version);
113+
start_time = new Date().getTime();
114+
js_output = exec(cmd).stdout;
115+
end_time = new Date().getTime();
116+
js_time = end_time - start_time;
117+
writeLog(' - [ShellJS '+version+'] took `' + js_time + '` milliseconds', prefix + '/' + jsfile);
118+
if (shell_output !== js_output) {
119+
writeLog('Output differs');
120+
}
121+
});
122+
90123
if (shell_time < js_time) {
91124
writeLog('Bash was `' + (js_time/shell_time).toFixed(3) + '` times faster than ShellJS');
92125
} else {
93126
writeLog('ShellJS was `' + (shell_time/js_time).toFixed(3) + '` times faster than Bash');
94127
shellJSWins.push(dir);
95128
}
96129

97-
if (shell_output !== js_output)
98-
writeLog('Output differs');
99-
100130
// Clean up
101131
echo('=======================');
102132
echo();
103133
config.silent = false;
104134
cd('..')
135+
// exit(7); // DEBUG: fix this
105136
});
106137

107138
if (shouldLog) {

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Benchmark ShellJS scripts",
55
"main": "index.js",
66
"scripts": {
7+
"install": "node scripts/install.js",
78
"test": "node benchmark.js"
89
},
910
"repository": {
@@ -20,8 +21,5 @@
2021
"bugs": {
2122
"url": "https://github.com/shelljs/benchmarks/issues"
2223
},
23-
"homepage": "https://github.com/shelljs/benchmarks#readme",
24-
"bin": {
25-
"benchmark": "./benchmark.js"
26-
}
24+
"homepage": "https://github.com/shelljs/benchmarks#readme"
2725
}

scripts/helloworld/helloworld.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

scripts/install.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
// Use v0.6.0, since this has no runtime dependency
3+
require('../shelljs/0.6.0');
4+
cd('shelljs');
5+
ls().forEach(function (k) {
6+
cd(k);
7+
exec('npm install --production');
8+
cd('..');
9+
});

shelljs/0.5.3/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"main": "index.js",
66
"dependencies": {
77
"shelljs": "^0.5.3"
8-
}
8+
},
9+
"repository": {},
10+
"license": "ISC"
911
}

shelljs/0.6.0/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"main": "index.js",
66
"dependencies": {
77
"shelljs": "^0.6.0"
8-
}
8+
},
9+
"repository": {},
10+
"license": "ISC"
911
}

shelljs/latest

Submodule latest added at da6d068

scripts/echoIntoFile/echoIntoFile.js renamed to test/echoIntoFile/echoIntoFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require('shelljs/global');
1+
require(process.argv[2]);
22
for (var k=0; k<1000; k++) {
33
'sometext\n'.to('testfile');
44
rm('testfile');

0 commit comments

Comments
 (0)
0