File: timing.c

package info (click to toggle)
sprng 2.0a-8
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 3,080 kB
  • ctags: 2,062
  • sloc: ansic: 30,350; fortran: 1,618; makefile: 573; cpp: 58; sh: 5
file content (75 lines) | stat: -rw-r--r-- 1,998 bytes parent folder | download | duplicates (9)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*--- Chris S.: June 10, 1999   */
/*---  reads in a generator type as an integer */
/*---adding 'int gentype' and read in + error handling */
/*--- generator numeral range is fix-set to 0-5 ?  */
/*--- should 5 be change to some variable MAX_GEN_NUMBER ? */
#include <stdio.h>
#include <stdlib.h>
#include "cputime.h"
#include "interface.h"

#define TIMING_TRIAL_SIZE 1000000
#define PARAM 0

main()
{

  int i;
  int *gen;
  double temp1, temp2, temp3, temp4;
  double temp_mult = TIMING_TRIAL_SIZE/1.0e6;
/*---   */
  int gentype;
  
  scanf("%d\n", &gentype);
  if((gentype < 0) || (gentype > 5))  /*--- range to be adjusted if needed */
  {
    printf("\nGenerator numeral out of range.\n\t...Exiting\n");    
    exit(1);
  }
/*---   */  


  gen = init_rng(gentype,0,1,0,PARAM);
/*--- Printing generator and stream information */
/*  print_rng(gen); */
  
  temp1 = cputime();

  for(i=0; i<TIMING_TRIAL_SIZE; i++)
    get_rn_int(gen);
  
  temp2 = cputime();
  

  for(i=0; i<TIMING_TRIAL_SIZE; i++)
    get_rn_flt(gen);
  
  temp3 = cputime();
  

  for(i=0; i<TIMING_TRIAL_SIZE; i++)
    get_rn_dbl(gen);
  
  temp4 = cputime();
  
  if(temp2-temp1 < 1.0e-15 || temp3-temp2 < 1.0e-15 ||  temp4-temp3 < 1.0e-15)
  {
    printf("Timing Information not available/not accurate enough.\n\t...Exiting\n");
    exit(1);
  }
  
  /* The next line is just used to ensure that the optimization does not remove the call to the RNG. Nothing is really printed.             */
  fprintf(stderr,"Last random number generated\n", get_rn_dbl(gen));

  printf("\nUser + System time Information (Note: MRS = Million Random Numbers Per Second)\n");
  printf("\tInteger generator:\t Time = %7.3f seconds => %8.4f MRS\n", 
	 temp2-temp1, temp_mult/(temp2-temp1));
  printf("\tFloat generator:\t Time = %7.3f seconds => %8.4f MRS\n", 
	 temp3-temp2, temp_mult/(temp3-temp2));
  printf("\tDouble generator:\t Time = %7.3f seconds => %8.4f MRS\n", 
	 temp4-temp3, temp_mult/(temp4-temp3));
  putchar('\n');
  
}