forked from mattgodbolt/jsbeeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d8js-bench.js
59 lines (55 loc) · 1.99 KB
/
d8js-bench.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
// To be run directly from 'js' or 'd8'.
"use strict";
///////////////////////////////////////////////////
// Enough of the code assumes there's a console.log that I've just made one here
var console = {
log: function () {
print.apply(console, arguments);
}
};
///////////////////////////////////////////////////
///////////////////////////////////////////////////
// Gook to simulate enough of requirejs to get Video to load
/* global load */
load('./lib/require.js');
requirejs.load = function (context, moduleName, url) {
load(url);
context.completeLoad(moduleName);
};
requirejs.config({
paths: {
'jsunzip': 'lib/jsunzip',
'promise': 'lib/promise-6.0.0',
'underscore': 'lib/underscore-min'
}
});
///////////////////////////////////////////////////
/* globals requirejs */
requirejs(['fake6502', 'fdc', 'models'],
function (Fake6502, disc, models) {
function benchmarkCpu(cpu, numCycles) {
numCycles = numCycles || 10 * 1000 * 1000;
console.log("Benchmarking over " + numCycles + " cpu cycles");
var startTime = Date.now();
cpu.execute(numCycles);
var endTime = Date.now();
var msTaken = endTime - startTime;
var virtualMhz = (numCycles / msTaken) / 1000;
console.log("Took " + msTaken + "ms to execute " + numCycles + " cycles");
console.log("Virtual " + virtualMhz.toFixed(2) + "MHz");
}
var discName = "elite";
var cpu = Fake6502.fake6502(models.findModel('B'));
cpu.initialise().then(function () {
return disc.load("discs/" + discName + ".ssd");
}).then(function (data) {
cpu.fdc.loadDisc(0, disc.discFor(cpu.fdc, '', data));
cpu.sysvia.keyDown(16);
cpu.execute(10 * 1000 * 1000);
cpu.sysvia.keyUp(16);
benchmarkCpu(cpu, 400 * 1000 * 1000);
}).catch(function (err) {
console.log("Got error: ", err);
});
}
);