From e02760f1b5ad6109db83b196c33d612d0ded7408 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 2 Aug 2011 16:40:44 +0200 Subject: [PATCH] use XBT portability layer to timing functions --- .../platforms/Evaluate_get_route_time.c | 52 +++---------------- .../simdag/platforms/Evaluate_parse_time.c | 43 ++++----------- 2 files changed, 17 insertions(+), 78 deletions(-) diff --git a/teshsuite/simdag/platforms/Evaluate_get_route_time.c b/teshsuite/simdag/platforms/Evaluate_get_route_time.c index a307d79638..02720c58d4 100644 --- a/teshsuite/simdag/platforms/Evaluate_get_route_time.c +++ b/teshsuite/simdag/platforms/Evaluate_get_route_time.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2008, 2009, 2010, 2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -11,7 +11,7 @@ #include #include "simdag/simdag.h" #include "surf/surf_private.h" -#include +#include "xbt/xbt_os_time.h" #define BILLION 1000000000L; extern routing_global_t global_routing; @@ -22,8 +22,7 @@ int main(int argc, char **argv) const SD_workstation_t *workstations; int i, j; int list_size; - struct timespec start, stop; - double accum; + xbt_os_timer_t timer = xbt_os_timer_new(); /* initialisation of SD */ SD_init(&argc, argv); @@ -34,20 +33,8 @@ int main(int argc, char **argv) workstations = SD_workstation_get_list(); list_size = SD_workstation_get_number(); - unsigned int seed; - struct timespec time; - //clock_gettime( CLOCK_REALTIME, &time); -#if _POSIX_TIMERS > 0 - clock_gettime(CLOCK_REALTIME, &time); -#else - struct timeval tv; - gettimeofday(&tv, NULL); - time.tv_sec = tv.tv_sec; - time.tv_nsec = tv.tv_usec*1000; -#endif - seed = time.tv_nsec; - - srand(seed); + /* Random number initialization */ + srand( (int) (xbt_os_time()*1000) ); do{ i = rand()%list_size; @@ -58,34 +45,11 @@ int main(int argc, char **argv) w2 = workstations[j]; printf("%d\tand\t%d\t\t",i,j); -#if _POSIX_TIMERS > 0 - if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { - perror( "clock gettime" ); - return EXIT_FAILURE; - } -#else - gettimeofday(&tv, NULL); - start.tv_sec = tv.tv_sec; - start.tv_nsec = tv.tv_usec*1000; -#endif - + xbt_os_timer_start(timer); SD_route_get_list(w1, w2); + xbt_os_timer_stop(timer); -#if _POSIX_TIMERS > 0 - if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) { - perror( "clock gettime" ); - return EXIT_FAILURE; - } -#else - gettimeofday(&tv, NULL); - stop.tv_sec = tv.tv_sec; - stop.tv_nsec = tv.tv_usec*1000; -#endif - - accum = ( stop.tv_sec - start.tv_sec ) - + (double)( stop.tv_nsec - start.tv_nsec ) - / (double)BILLION; - printf("%lf\n", accum); + printf("%lf\n", xbt_os_timer_elapsed(timer) ); SD_exit(); diff --git a/teshsuite/simdag/platforms/Evaluate_parse_time.c b/teshsuite/simdag/platforms/Evaluate_parse_time.c index 3340d38b2b..d79e47ea6d 100644 --- a/teshsuite/simdag/platforms/Evaluate_parse_time.c +++ b/teshsuite/simdag/platforms/Evaluate_parse_time.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2008, 2009, 2010, 2011. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,49 +10,24 @@ #include #include "simdag/simdag.h" #include "surf/surf_private.h" -#include +#include "xbt/xbt_os_time.h" -#define BILLION 1000000000L; extern routing_global_t global_routing; int main(int argc, char **argv) { - struct timespec start, stop; - double accum; + xbt_os_timer_t timer = xbt_os_timer_new(); - /* initialisation of SD */ + /* initialization of SD */ SD_init(&argc, argv); -#if _POSIX_TIMERS > 0 - if( clock_gettime( CLOCK_REALTIME, &start) == -1 ) { - perror( "clock gettime" ); - return EXIT_FAILURE; - } -#else - struct timeval tv; - gettimeofday(&tv, NULL); - start.tv_sec = tv.tv_sec; - start.tv_nsec = tv.tv_usec*1000; -#endif - /* creation of the environment */ + /* creation of the environment, timed */ + xbt_os_timer_start(timer); SD_create_environment(argv[1]); + xbt_os_timer_stop(timer); -#if _POSIX_TIMERS > 0 - if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ) { - perror( "clock gettime" ); - return EXIT_FAILURE; - } -#else - gettimeofday(&tv, NULL); - stop.tv_sec = tv.tv_sec; - stop.tv_nsec = tv.tv_usec*1000; -#endif - - accum = ( stop.tv_sec - start.tv_sec ) - + (double)( stop.tv_nsec - start.tv_nsec ) - / (double)BILLION; - - printf( "%lf\n", accum ); + /* Display the result and exit after cleanup */ + printf( "%lf\n", xbt_os_timer_elapsed(timer) ); sleep(20); -- 2.20.1