forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
/
benchmark.js
64 lines (50 loc) · 5.6 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
var fs = require('fs');
var test = require('tape');
var DataURItoBuffer = require('data-uri-to-buffer');
require('events').EventEmitter.prototype.setMaxListeners(100);
ImageSequencer = require('../../../src/ImageSequencer.js');
var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAAKUElEQVR4Ae2dsW6cVRCFvYi0IQ00ltJG4gGcIsAL0JAnoKNFspTKBXKRiiptOto0RJF4gUADD4DFA6QxVWqQwFDtL90jeaRzvTv3fFS747vjme/8hyvNzV7vXr05P+G/wxF4cHF1uF/Obz75AAYQSCaAAZLVp3d2AJ6BbALsANn6x3ePAeIfgWwAGCBb//juMUD8I5AN4MNq+z88+730ka+//3S43pVnmPwm6MrvyqPqrMY/+fKs9JHrn34brnflGSa/Cbryu/KoOtkBFBniEQQwQITMNKkIYABFhngEAQwQITNNKgIYQJEhHkEAA0TITJOKAAZQZIhHEJDnANX5dwStWzSpuKnzEJWyOv9WedLiips6D2EHSHtC6HdDAANscPAmjQAGSFOcfjcEMMAGB2/SCGCANMXpd0MAA2xw8CaNAAZIU5x+NwTkOYCaW6s59ybr3pvq+r2P3ulLV52KW7UZNbdWc26Vv7pe5Zkdd9WpuKn62QEUGeIRBDBAhMw0qQhgAEWGeAQBDBAhM00qAhhAkSEeQQADRMhMk4oABlBkiEcQkOcArrn4t1+9K4F88fq0tL66eHY9ilv1fMA1F7/48dcSoudPH5fWVxfPrkdxU+cD7ABVBVm/FAEMsJScNFMlgAGqxFi/FAEMsJScNFMlgAGqxFi/FAEMsJScNFMlgAGqxFi/FAF5DlCdW6v591K09p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qnF30Hyy3tzpZ+d34WIHcBFkjwtCWCAlrJRtIsABnCRJE9LAhigpWwU7SKAAVwkydOSAAZoKRtFuwhgABdJ8rQkYBsGq/vyXVSqfx9gdj2uvlx51H35rvzVvw8wux5XX+wALpLkaUkAA7SUjaJdBDCAiyR5WhLAAC1lo2gXAQzgIkmelgQwQEvZKNpFAAO4SJKnJQHbOYCrezXvr973f3Iy/r5B2vlAVRc17y/f93/6aPirj+18gB1gKBPBFAIYIEVp+hwSwABDLARTCGCAFKXpc0gAAwyxEEwhgAFSlKbPIQEMMMRCMIXAwc4BfPP+sVT63IDzgf+Iueb9Y/onJ+rc4PLIzgfYAZSCxCMIYIAImWlSEcAAigzxCAIYIEJmmlQEMIAiQzyCAAaIkJkmFQEMoMgQjyBQPgdQ83vXv7Pvcq+/4jD7qVHze9e/s+9yr7/iUOXPDlAlxvqlCGCApeSkmSoBDFAlxvqlCGCApeSkmSoBDFAlxvqlCGCApeSkmSoBDFAlxvqlCOzuP3m4VEPdmtldn3Ureal62QGWkpNmqgQwQJUY65cigAGWkpNmqgQwQJUY65cigAGWkpNmqgQwQJUY65cigAGWkpNmqgT+BUuiXJxW3owHAAAAAElFTkSuQmCC';
var imageName = 'image1';
test('benchmark all modules', function(t) {
var sequencerDefault = ImageSequencer({ ui: false, inBrowser: false, useWasm:false });
console.log('############ Benchmarks ############');
runBenchmarks(sequencerDefault, t);
console.log('####################################');
});
test('benchmark all modules with WebAssembly', function(t) {
var sequencerWebAssembly = ImageSequencer({ ui: false, inBrowser: false, useWasm: true });
console.log('############ Benchmarks with WebAssembly ############');
runBenchmarks(sequencerWebAssembly, t);
console.log('####################################');
});
function runBenchmarks(sequencer, t) {
var mods = Object.keys(sequencer.modules);
sequencer.loadImages(image);
while ((mods[0] === 'import-image' || (!!sequencer.modulesInfo(mods[0]).requires && sequencer.modulesInfo(mods[0]).requires.includes('browser'))))
mods.splice(0, 1);
sequencer.addSteps(mods[0]);
global.start = Date.now();
global.idx = 0;
sequencer.run(cb);
function cb() {
var end = Date.now();
console.log('Module ' + mods[0] + ' ran in: ' + (end - global.start) + ' milliseconds');
if (mods.length > 1) { // Last one is test module, we need not benchmark it
sequencer.steps[global.idx].output.src = image;
global.idx++;
mods.splice(0, 1);
while (mods[0] === 'import-image' || mods[0] === 'minify-image' || (!!sequencer.modulesInfo(mods[0]).requires && sequencer.modulesInfo(mods[0]).requires.includes('webgl'))) {
/* Not currently working for this module, which is for importing a new image */
console.log(`Bypassing ${mods[0]}`);
mods.splice(0, 1);
}
sequencer.addSteps(mods[0]);
global.start = Date.now();
sequencer.run({ index: global.idx }, cb);
}
else {
t.end();
}
}
}