File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ const assert = require('assert');
2424const pid = proc . pid ;
2525
2626var time = 0 ;
27- const TRIALS = 1000 ;
27+ const TRIALS = 200 ;
28+ const MAX_FAILURES = 5 ;
2829var failures = 0 ;
2930for ( let i = 0 ; i < TRIALS ; i ++ ) {
3031 let new_time = ps . cpuTime ( pid ) ;
@@ -36,14 +37,14 @@ for (let i = 0; i < TRIALS; i++) {
3637 // And do some extra computation to make sure we get more time.
3738 let v = 1 + Math . random ( ) ;
3839 let u = '{"a": 1}' ;
39- for ( let j = 0 ; j < 1000 ; j ++ ) {
40- v = Math . hypot ( v , Math . random ( ) , Math . random ( ) ) ;
40+ for ( let j = 0 ; j < 10000 ; j ++ ) {
41+ v = eval ( " Math.hypot(v, Math.random(), Math.random())" ) ;
4142 let c = JSON . parse ( u ) ;
4243 c [ String . fromCharCode ( 97 + Math . floor ( j * v ) % 26 ) ] = v ;
4344 u = JSON . stringify ( c ) ;
4445 }
4546}
46- if ( TRIALS * 0.01 < failures ) {
47+ if ( failures > MAX_FAILURES ) {
4748 throw new Error ( 'Too many failures: ' + failures + '/' + TRIALS ) ;
4849} else {
4950 console . log ( 'Basic CPU time test passed with only ' + failures + '/' + TRIALS + ' failures.' ) ;
You can’t perform that action at this time.
0 commit comments