8000 Adding logging functionality to `benchmark.js log` · shelljs/benchmarks@b5867f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5867f6

Browse files
committed
Adding logging functionality to benchmark.js log
1 parent 19e5ec8 commit b5867f6

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,69 @@ It works by running shell utilities and timing the speed of completion for each
66
tested utility.
77

88
This will comprise every shell utility ShellJS supports.
9+
10+
## Results
11+
12+
### [echoIntoFile](scripts/echoIntoFile)
13+
14+
- [ShellJS](scripts/echoIntoFile/echoIntoFile.js) took `271` milliseconds
15+
16+
- [Bash](scripts/echoIntoFile/echoIntoFile.sh) took `871` milliseconds
17+
18+
ShellJS was `3.214` times faster than Bash
19+
20+
### [envVariable](scripts/envVariable)
21+
22+
- [ShellJS](scripts/envVariable/envVar.js) took `1237` milliseconds
23+
24+
- [Bash](scripts/envVariable/envVar.sh) took `1178` milliseconds
25+
26+
Bash was `1.050` times faster than ShellJS
27+
28+
### [forLoopAlternateSyntax](scripts/forLoopAlternateSyntax)
29+
30+
- [ShellJS](scripts/forLoopAlternateSyntax/helloworld10k.js) took `180` milliseconds
31+
32+
- [Bash](scripts/forLoopAlternateSyntax/helloworld10k.sh) took `97` milliseconds
33+
34+
Bash was `1.856` times faster than ShellJS
35+
36+
### [helloworld](scripts/helloworld)
37+
38+
- [ShellJS](scripts/helloworld/helloworld.js) took `159` milliseconds
39+
40+
- [Bash](scripts/helloworld/helloworld.sh) took `83` milliseconds
41+
42+
Bash was `1.916` times faster than ShellJS
43+
44+
### [helloworld10k](scripts/helloworld10k)
45+
46+
- [ShellJS](scripts/helloworld10k/helloworld10k.js) took `293` milliseconds
47+
48+
- [Bash](scripts/helloworld10k/helloworld10k.sh) took `168` milliseconds
49+
50+
Bash was `1.744` times faster than ShellJS
51+
52+
### [ls10k](scripts/ls10k)
53+
54+
- [ShellJS](scripts/ls10k/ls10k.js) took `827` milliseconds
55+
56+
- [Bash](scripts/ls10k/ls10k.sh) took `9679` milliseconds
57+
58+
ShellJS was `11.704` times faster than Bash
59+
60+
### [pwd10k](scripts/pwd10k)
61+
62+
- [ShellJS](scripts/pwd10k/path10k.js) took `2072` milliseconds
63+
64+
- [Bash](scripts/pwd10k/path10k.sh) took `679` milliseconds
65+
66+
Bash was `3.052` times faster than ShellJS
67+
68+
### [touchSyntax06](scripts/touchSyntax06)
69+
70+
- [ShellJS](scripts/touchSyntax06/touchrm10k.js) took `293` milliseconds
71+
72+
- [Bash](scripts/touchSyntax06/touchrm10k.sh) took `1447` milliseconds
73+
74+
ShellJS was `4.939` times faster than Bash

benchmark.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ require('shelljs/global');
33

44
var TEST_DIR = 'scripts';
55

6+
var shouldLog = (process.argv[2] === 'log');
7+
var log = [];
8+
9+
function writeLog(msg, link) {
10+
console.log(msg);
11+
if (link) {
12+
msg = msg.replace(']', '](' + link + ')');
13+
}
14+
log.push(msg);
15+
}
16+
617
cd(__dirname + '/' + TEST_DIR);
18+
var prefix;
719
ls().forEach(function (dir) {
8-
echo(dir)
20+
prefix = TEST_DIR + '/' + dir;
21+
writeLog('### [' + dir + ']', prefix)
922
cd(dir)
1023

1124
// Find the files
@@ -31,28 +44,37 @@ ls().forEach(function (dir) {
3144
js_output = exec('node ' + jsfile).output;
3245
end_time = new Date().getTime();
3346
js_time = end_time - start_time;
34-
echo('> ShellJS took ' + js_time + ' milliseconds');
47+
writeLog(' - [ShellJS] took `' + js_time + '` milliseconds', prefix + '/' + jsfile);
3548

3649
start_time = new Date().getTime();
3750
shell_output = exec('bash ' + shfile).output;
3851
end_time = new Date().getTime();
3952
shell_time = end_time - start_time;
40-
echo('> Bash took ' + shell_time + ' milliseconds');
53+
writeLog(' - [Bash] took `' + shell_time + '` milliseconds', prefix + '/' + shfile);
4154

4255
if (shell_time < js_time) {
43-
echo('Bash won');
44-
echo('Bash was ' + (js_time/shell_time).toFixed(3) + ' times faster than ShellJS');
56+
writeLog('Bash was `' + (js_time/shell_time).toFixed(3) +  9E7A 9;` times faster than ShellJS');
4557
} else {
46-
echo('ShellJS won!!');
47-
echo('ShellJS was ' + (shell_time/js_time).toFixed(3) + ' times faster than Bash');
58+
writeLog('ShellJS was `' + (shell_time/js_time).toFixed(3) + '` times faster than Bash');
4859
}
4960

5061
if (shell_output !== js_output)
51-
echo('Output differs');
62+
writeLog('Output differs');
5263

5364
// Clean up
5465
echo('=======================');
5566
echo();
5667
config.silent = false;
5768
cd('..')
5869
});
70+
71+
if (shouldLog) {
72+
cd(__dirname);
73+
var text = log.join('\n\n');
74+
75+
// Wipe out the old results
76+
cat('README.md').replace(/## Results(.|\n)*/, '## Results').to('README.md');
77+
78+
// Append new docs to README
79+
sed('-i', /## Results/, '## Results\n\n' + text, 'README.md');
80+
}

0 commit comments

Comments
 (0)
0