-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathexercise.js
39 lines (29 loc) · 1.07 KB
/
exercise.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
"use strict"
var input = require('../../input')
module.exports = input().wrap(function(input, repeat) {
var count = 0
var CYCLES = 100000
function operation() {
for (var i = 0; i < 1000000; i++) {} // burn some CPU cycles
count++ // count how many times this function was called
}
console.log()
console.log('the operation:')
console.log(operation.toString())
console.log()
console.log('Trying to repeat the operation %d times...', CYCLES)
console.log('Press control+c to kill.')
console.log()
var start = Date.now()
repeat(operation, CYCLES)
setTimeout(function() {
var end = Date.now()
console.error('Performed %d operations.', count)
if (count === CYCLES) console.log('Fail! Should not have completed all operations!')
// TODO calculate ideal ops per second?
//if (count < 1000) console.log('Fail! Should have performed more operations!')
if (end - start < 1500) console.log('Interrupted in approximately 1 second!')
else console.log('Fail! Interrupted in %d milliseconds', end - start)
process.exit()
}, 1000)
})