Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
139 user(s) are online (72 user(s) are browsing Forums)

Members: 1
Guests: 138

pvanni, more...

Headlines

 
  Register To Post  

How to measure program execution time?
Just can't stay away
Just can't stay away


See User information
Is there anything like "time" command (Linux) on AmigaOS 4? I wrote a simple tool that uses gettimeofday() + system() to get some figures but maybe there are better tools already?

Here is the source, very little tested:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

static char buffer[1024];

int main(int argcchar** argv)
{
    for (
int i 1argci++) {
        
int len strlen(buffer);
        
snprintf(buffer lensizeof(buffer) - len"%s "argv[i]);
    }

    
//printf("buffer '%s'\n", buffer);

    
struct timeval beforeafter;

    
gettimeofday(&beforeNULL);

    
int result system(buffer);

    
gettimeofday(&afterNULL);

    
uint32_t duration = (after.tv_sec before.tv_sec) * 1000000 + (after.tv_usec before.tv_usec);

    
printf("\nCommand result %d. Duration [%u] microseconds or [%u] milliseconds\n"resultdurationduration 1000);

    return 
0;
}

Go to top
Re: How to measure program execution time?
Amigans Defender
Amigans Defender


See User information
In clib2 there are a lot of new functions to measure time.
For example in test_programs/memory/string_benchmark.c you have somthing like:

clock_t begin = clock();
//DO STUFF
clock_t end = clock();
double time_spent = (double) (end - begin) / CLOCKS_PER_SEC;
printf("%lf secs\n", time_spent);

But there are other examples too both for c++ and c

i'm really tired...
Go to top
Re: How to measure program execution time?
Home away from home
Home away from home


See User information
@Capehill

If you test your stuff mostly from the shell you could add this to your shell's tooltypes
WINDOW=CON:0/0/500/300/AmigaShell - (Elapsed Time: %E)/CLOSE/TABBED

This will show the time the last command you started took in the shell window's top bar...i wouldn't miss it, great little helper

NB: adapt the winodw size and position to your liking

edit: oh, you probably looked for something that could be used in code :-/

People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Go to top
Re: How to measure program execution time?
Just can't stay away
Just can't stay away


See User information
@Raziel

I was looking for something that works like this:

Shell> time wait 3

Duration 3010 ms.

Shell> time make -f something.make

Duration 10503 ms.

So the purpose is to time random executables or scripts.

Go to top
Re: How to measure program execution time?
Not too shy to talk
Not too shy to talk


See User information
Hey guys,

There's a built-in functionality in the Shell to record the
execution time of a preceding command. It's stored in an
environment variable and you can just run this after the
command in question:

echo $_runtime

Does that suffice?

Thanks,

PJS

Go to top
Re: How to measure program execution time?
Home away from home
Home away from home


See User information
@Capehill

Then the shell solution i described above should suffice...i just tried your example

> wait 3
and shell output after the execution was
Quote:

Elapsed Time: 3,192.523


edit: or what Paul said

People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Go to top
Re: How to measure program execution time?
Just can't stay away
Just can't stay away


See User information
Or go crazy like me and have this line (or elements thereof ) in your Shell-Startup:

prompt "*E[33m%N.%S %R %W [%E] *`C:Date` *n$ *E[31m"

Best regards,

Niels

Go to top
Re: How to measure program execution time?
Just can't stay away
Just can't stay away


See User information
Thanks all, learned new things again. Seems there is no need to reinvent wheels here.

Go to top
Re: How to measure program execution time?
Just can't stay away
Just can't stay away


See User information
@Capehill

I use "utility/shell/timer.lha" from OS4Depot.

timer <command> starts <command> and displays how long it took to execute.

Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project