Rate counter: Difference between revisions

m
Fix the sort order, since I changed the language header name...
(Cleaned up description somewhat.)
m (Fix the sort order, since I changed the language header name...)
Line 9:
 
Be aware of the precision and accuracy limitations of your timing mechanisms, and document them if you can.
 
=={{header|UNIX Shell}}==
This code stores the number of times the program '''task''' can complete in 20 seconds. It is two parts.
 
Part 1: file "foo.sh"
 
This script spins, executing '''task''' as many times as possible.
<lang bash>
#!/bin/bash
 
while : ; do
task && echo >> .fc
done
</lang>
 
Part 2:
This script runs '''foo.sh''' in the background, and checks the rate count file every five seconds. After four such checks, twenty seconds will have elapsed.
<lang bash>
./foo.sh &
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
rm .fc2
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
sleep 5
killall foo.sh
wc -l .fc 2>/dev/null
rm .fc
</lang>
 
=={{header|C}}==
Line 209 ⟶ 175:
return 0;
}
</lang>
 
=={{header|UNIX Shell}}==
This code stores the number of times the program '''task''' can complete in 20 seconds. It is two parts.
 
Part 1: file "foo.sh"
 
This script spins, executing '''task''' as many times as possible.
<lang bash>
#!/bin/bash
 
while : ; do
task && echo >> .fc
done
</lang>
 
Part 2:
This script runs '''foo.sh''' in the background, and checks the rate count file every five seconds. After four such checks, twenty seconds will have elapsed.
<lang bash>
./foo.sh &
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
rm .fc2
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
sleep 5
mv .fc .fc2 2>/dev/null
wc -l .fc2 2>/dev/null
sleep 5
killall foo.sh
wc -l .fc 2>/dev/null
rm .fc
</lang>