File: clock_of.c

package info (click to toggle)
mcpp 2.5-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,544 kB
  • ctags: 28,000
  • sloc: ansic: 34,825; sh: 3,812; makefile: 120; cpp: 84; exp: 18
file content (45 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* clock_of.c:  to measure the execution time of a program. */
/* 2002/08      kmatsui */

#include    "stdio.h"
#include    "stdlib.h"
#include    "string.h"
#include    "time.h"

void    usage( void);

int     main( int argc, char ** argv)
{
    char    command[ BUFSIZ];
    char    **arg, *buf;
    long    start_time, passed_time;
    int     ret;

    if (argc < 2)
        usage();
    ret = -1;
    arg = argv;
    buf = command;
    while (*++arg) {
        sprintf( buf, "%s ", *arg);
        buf += strlen( buf);
    }
    fprintf( stderr, "%s\n", command);
    start_time = clock();
    ret = system( command);
    if (ret == 0) {
        passed_time = clock() - start_time;
        fprintf( stderr, "%ld ticks passed (%f seconds).\n"
                , passed_time, (double) passed_time / CLOCKS_PER_SEC);
    } else {
        fprintf( stderr, "Command execution error! (status: %d)\n", ret);
    }

    return 0;
}

void    usage( void)
{
    fputs( "usage: clock_of <command> [<args>]\n", stderr);
    exit( 1);
}