Jump to content

Rate counter: Difference between revisions

Add Jsish
(Add Jsish)
Line 845:
return times;
}</lang>
 
=={{header|Jsish}}==
<lang javascript>#!/usr/bin/env jsish
"use strict";
/* Rate counter, timer access, in Jsish */
 
/* System time in milliseconds */
var milliSeconds = strptime();
var runs = 0;
function spinCycles () {
sleep(Math.random());
}
var newMs;
while ((newMs = strptime()) < (milliSeconds + 1000)) { runs += 1; }
puts(runs, 'runs in', newMs - milliSeconds, 'ms');
 
 
/* Builtin times test(callback, runs), result in microseconds */
function sleeper() { sleep(10); }
 
var timer;
for (var i = 1; i < 4; i++) {
timer = times(sleeper, 100);
puts(timer, 'μs to sleep 10 ms, 100 times');
}</lang>
 
{{out}}
<pre>
prompt$ jsish rateCounter.jsi
117432 runs in 1000 ms
1018530 μs to sleep 10 ms, 100 times
1019219 μs to sleep 10 ms, 100 times
1018895 μs to sleep 10 ms, 100 times</pre>
 
=={{header|Julia}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.