How to resolve the algorithm Time a function step by step in the Aime programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Time a function step by step in the Aime programming language
Table of Contents
Problem Statement
Write a program which uses a timer (with the least granularity available on your system) to time how long a function takes to execute. Whenever possible, use methods which measure only the processing time used by the current process; instead of the difference in system time between start and finish, which could include time used by other processes on the computer. This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Time a function step by step in the Aime programming language
Source code in the aime programming language
integer
identity(integer x)
{
x;
}
integer
sum(integer c)
{
integer s;
s = 0;
while (c) {
s += c;
c -= 1;
}
s;
}
real
time_f(integer (*fp)(integer), integer fa)
{
date f, s;
time t;
s.now;
fp(fa);
f.now;
t.ddiff(f, s);
t.microsecond / 1000000r;
}
integer
main(void)
{
o_real(6, time_f(identity, 1));
o_text(" seconds\n");
o_real(6, time_f(sum, 1000000));
o_text(" seconds\n");
0;
}
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the F# programming language
You may also check:How to resolve the algorithm Thiele's interpolation formula step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the ALGOL 60 programming language
You may also check:How to resolve the algorithm String comparison step by step in the Raku programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Scala programming language