Files
TempleOS-Rijn/LT/Demo/TimeIns.CPZ
T
2018-09-08 21:45:20 +02:00

52 lines
1.1 KiB
Plaintext

/*
$FG,2$This program allows you to measure the
timing of various instructions.
Don't be surprised by odd results
because the CPU does instructions in
parallel sometimes and a simple
instruction might take place in parallel
with the loop instruction and it will
report zero clock cycles.
$FG$*/
#define SAMPLE_SIZE 100000000
void TimeIns()
{
I8 i;
U8 start1,end1,start2,end2,overhead_time,test_time;
double reg d=5.0; //$FG,2$Use the $FG,4$reg$FG,2$ directive to designate register variables$FG$
Preempt(OFF);
//Measure Loop Overhead
start1=GetTimeStamp;
for (i=0;i<SAMPLE_SIZE;i++) {
}
end1=GetTimeStamp;
overhead_time=end1-start1;
start2=GetTimeStamp;
for (i=0;i<SAMPLE_SIZE;i++) {
$FG,4$#exe {OPassTraceMask(0b100000000);OTrace(ON);}
//$FG,2$Put your test instructions here.$FG,4$
d*=1.00001;
#exe {OTrace(OFF);}
$FG$ }
end2=GetTimeStamp;
test_time=end2-start2;
PrintF("\r\n\r\n\r\nCycles %10.5f\r\n",
(test_time-overhead_time)*1.0/SAMPLE_SIZE);
Preempt(ON);
}
TimeIns;