Advertisement
Guest User

Untitled

a guest
Nov 1st, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. #define REPEAT (1000 * 10000)
  7.  
  8. static void a1( double a )
  9. {
  10.         static char b[30];
  11.         char * p;
  12.  
  13.         sprintf (b, "%f", a);  
  14.         p = strchr (b, '.');
  15.         if (p) *p=',';
  16.        
  17.         printf ("%s", b);
  18. }
  19.  
  20. static void a2( double a )
  21. {
  22.     static char loc = ',';
  23.  
  24.     printf( "%d%c%d", (int)a, loc, (int)((a-(int)a)*1000000) );
  25. }
  26.  
  27. int main()
  28. {
  29.     unsigned int i, j = (unsigned int)time(NULL);
  30.     for( i = 0; i < REPEAT; i++ ) a1( 92.2345 );
  31.     printf( "\na1: %u\n", (unsigned int)time(NULL) - j );
  32.     for( i = 0; i < REPEAT; i++ ) a2( 92.2345 );
  33.     j = (unsigned int)time(NULL);
  34.     printf( "\na2: %u\n", (unsigned int)time(NULL) - j );
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement