/******************************************************* * Tune all the threshold of MPFR * * Warning: tune the function in their dependent order!* *******************************************************/ static void all (void) { FILE *f = stdout; time_t start_time, end_time; struct tm *tp; speed_time_init (); if (verbose) { printf ("Using: %s\n", speed_time_string); printf ("speed_precision %d", speed_precision); if (speed_unittime == 1.0) printf (", speed_unittime 1 cycle"); else printf (", speed_unittime %.2e secs", speed_unittime); if (speed_cycletime == 1.0 || speed_cycletime == 0.0) printf (", CPU freq unknown\n"); else printf (", CPU freq %.2f MHz\n\n", 1e-6/speed_cycletime); } time (&start_time); tp = localtime (&start_time); fprintf (f, "/* Generated by MPFR's tuneup.c, %d-%02d-%02d, ", tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday); #ifdef __ICC fprintf (f, "icc %d.%d.%d */\n", __ICC / 100, __ICC / 10 % 10, __ICC % 10); #elif defined(__GNUC__) fprintf (f, "gcc %d.%d */\n", __GNUC__, __GNUC_MINOR__); #elif defined (__SUNPRO_C) fprintf (f, "Sun C %d.%d */\n", __SUNPRO_C / 0x100, __SUNPRO_C % 0x100); #elif defined (__sgi) && defined (_COMPILER_VERSION) fprintf (f, "MIPSpro C %d.%d.%d */\n", _COMPILER_VERSION / 100, _COMPILER_VERSION / 10 % 10, _COMPILER_VERSION % 10); #elif defined (__DECC) && defined (__DECC_VER) fprintf (f, "DEC C %d */\n", __DECC_VER); #else fprintf (f, "system compiler */\n"); #endif fprintf (f, "\n"); /* Tune mpfr_mul (threshold is in limbs, but it doesn't matter too much) */ if (verbose) printf ("Measuring mpfr_mul with mpfr_mul_threshold=%lu...\n", mpfr_mul_threshold); tune_simple_func (&mpfr_mul_threshold, speed_mpfr_mul, 2*GMP_NUMB_BITS+1, 1000); /* End of tuning */ time (&end_time); if (verbose) printf ("Complete (took %ld seconds).\n", end_time - start_time); }
void start_timing(void) { if(seconds_per_cycle == 0.0) speed_time_init(); if(need_cycles) { lock_thread_to_core(); start = __rdtsc(); } else { LARGE_INTEGER ll; QueryPerformanceCounter(&ll); start = seconds_per_tick * ll.QuadPart; } }
int main(void) { char b1[_MAX_PATH], b2[_MAX_PATH]; unsigned long long cps; if(get_processor_info(b1, b2, &cps) == EXIT_SUCCESS) { speed_time_init(); printf("\n%s", b1); printf("\n%s", b2); printf("\nSpeed: %lld", cps); printf("\nSpeed: %.0f", 1.0 / seconds_per_cycle); return 0; } else return EXIT_FAILURE; }
int main (int argc, char *argv[]) { int i; int opt; /* Unbuffered so output goes straight out when directed to a pipe or file and isn't lost on killing the program half way. */ setbuf (stdout, NULL); for (;;) { #if _GNU_SOURCE opt = getopt(argc, argv, "a:CcDd::EFf:o:p:P:r::Rs:t:ux:y:w:W:z"); #else opt = getopt(argc, argv, "a:CcDd:EFf:o:p:P:r:Rs:t:ux:y:w:W:z"); #endif if (opt == EOF) break; switch (opt) { case 'a': if (strcmp (optarg, "random") == 0) option_data = DATA_RANDOM; else if (strcmp (optarg, "random2") == 0) option_data = DATA_RANDOM2; else if (strcmp (optarg, "zeros") == 0) option_data = DATA_ZEROS; else if (strcmp (optarg, "aas") == 0) option_data = DATA_AAS; else if (strcmp (optarg, "ffs") == 0) option_data = DATA_FFS; else if (strcmp (optarg, "2fd") == 0) option_data = DATA_2FD; else { fprintf (stderr, "unrecognised data option: %s\n", optarg); exit (1); } break; case 'C': if (option_unit != UNIT_SECONDS) goto bad_unit; option_unit = UNIT_CYCLESPERLIMB; break; case 'c': if (option_unit != UNIT_SECONDS) { bad_unit: fprintf (stderr, "cannot use more than one of -c, -C\n"); exit (1); } option_unit = UNIT_CYCLES; break; case 'D': if (option_cmp != CMP_ABSOLUTE) goto bad_cmp; option_cmp = CMP_DIFFPREV; break; case 'd': if (option_cmp != CMP_ABSOLUTE) { bad_cmp: fprintf (stderr, "cannot use more than one of -d, -D, -r\n"); exit (1); } option_cmp = CMP_DIFFERENCE; option_cmp_pos=0; if(optarg!=0)option_cmp_pos=atoi(optarg)-1; break; case 'E': option_square = 1; break; case 'F': option_square = 2; break; case 'f': option_factor = atof (optarg); if (option_factor <= 1.0) { fprintf (stderr, "-f factor must be > 1.0\n"); exit (1); } break; case 'o': speed_option_set (optarg); break; case 'P': option_gnuplot = 1; option_gnuplot_basename = optarg; break; case 'p': speed_precision = atoi (optarg); break; case 'R': option_seed = time (NULL); break; case 'r': if (option_cmp != CMP_ABSOLUTE) goto bad_cmp; option_cmp = CMP_RATIO; option_cmp_pos=0; if(optarg!=0)option_cmp_pos = atoi(optarg)-1; break; case 's': { char *s; for (s = strtok (optarg, ","); s != NULL; s = strtok (NULL, ",")) { if (size_num == size_allocnum) { size_array = (struct size_array_t *) __gmp_allocate_or_reallocate (size_array, size_allocnum * sizeof(size_array[0]), (size_allocnum+10) * sizeof(size_array[0])); size_allocnum += 10; } size_array[size_num].inc = 0; if (sscanf (s, "%ld(%ld)%ld", &size_array[size_num].start, &size_array[size_num].inc, &size_array[size_num].end) != 3) { if (sscanf (s, "%ld-%ld", &size_array[size_num].start, &size_array[size_num].end) != 2) { size_array[size_num].start = size_array[size_num].end = atol (s); } } if (size_array[size_num].start < 0 || size_array[size_num].end < 0 || size_array[size_num].start > size_array[size_num].end) { fprintf (stderr, "invalid size parameter: %s\n", s); exit (1); } size_num++; } } break; case 't': option_step = atol (optarg); if (option_step < 1) { fprintf (stderr, "-t step must be >= 1\n"); exit (1); } break; case 'u': option_resource_usage = 1; break; case 'z': sp.cache = 1; break; case 'x': sp.align_xp = atol (optarg); check_align_option ("-x", sp.align_xp); break; case 'y': sp.align_yp = atol (optarg); check_align_option ("-y", sp.align_yp); break; case 'w': sp.align_wp = atol (optarg); check_align_option ("-w", sp.align_wp); break; case 'W': sp.align_wp2 = atol (optarg); check_align_option ("-W", sp.align_wp2); break; case '?': exit(1); } } if (optind >= argc) { usage (); exit (1); } if (size_num == 0) { fprintf (stderr, "-s <size> must be specified\n"); exit (1); } gmp_randinit_default (__gmp_rands); __gmp_rands_initialized = 1; gmp_randseed_ui (__gmp_rands, option_seed); choice = (struct choice_t *) (*__gmp_allocate_func) ((argc - optind) * sizeof(choice[0])); for ( ; optind < argc; optind++) { struct choice_t c; routine_find (&c, argv[optind]); choice[num_choices] = c; num_choices++; } if ((option_cmp == CMP_RATIO || option_cmp == CMP_DIFFERENCE) && num_choices < 2) { fprintf (stderr, "WARNING, -d or -r does nothing when only one routine requested\n"); } speed_time_init (); if (option_unit == UNIT_CYCLES || option_unit == UNIT_CYCLESPERLIMB) speed_cycletime_need_cycles (); else speed_cycletime_need_seconds (); if (option_gnuplot) { run_gnuplot (argc, argv); } else { if (option_unit == UNIT_SECONDS) printf ("overhead %.9f secs", speed_measure (speed_noop, NULL)); else printf ("overhead %.2f cycles", speed_measure (speed_noop, NULL) / speed_cycletime); printf (", precision %d units of %.2e secs", speed_precision, speed_unittime); if (speed_cycletime == 1.0 || speed_cycletime == 0.0) printf (", CPU freq unknown\n"); else printf (", CPU freq %.2f MHz\n", 1e-6/speed_cycletime); printf (" "); for (i = 0; i < num_choices; i++) printf (" %*s", COLUMN_WIDTH, choice[i].name); printf ("\n"); run_all (stdout); } if (option_resource_usage) { #if HAVE_GETRUSAGE { /* This doesn't give data sizes on linux 2.0.x, only utime. */ struct rusage r; if (getrusage (RUSAGE_SELF, &r) != 0) perror ("getrusage"); else printf ("getrusage(): utime %ld.%06ld data %ld stack %ld maxresident %ld\n", r.ru_utime.tv_sec, r.ru_utime.tv_usec, r.ru_idrss, r.ru_isrss, r.ru_ixrss); } #else printf ("getrusage() not available\n"); #endif /* Linux kernel. */ { char buf[128]; sprintf (buf, "/proc/%d/status", getpid()); if (access (buf, R_OK) == 0) { sprintf (buf, "cat /proc/%d/status", getpid()); system (buf); } } } return 0; }
void usage (void) { int i; speed_time_init (); printf ("Usage: speed [-options] -s size <routine>...\n"); printf ("Measure the speed of some routines.\n"); printf ("Times are in seconds, accuracy is shown.\n"); printf ("\n"); printf (" -p num set precision as number of time units each routine must run\n"); printf (" -s x [,x]... sizes to measure: x = <size> | <start-end> | <start(step)end>\n"); printf (" single sizes or ranges, sep with comma or use multiple -s\n"); printf (" -t step step through sizes by given amount\n"); printf (" -f factor step through sizes by given factor (eg. 1.05)\n"); #if _GNU_SOURCE printf (" -r [col] show times as ratios of the routine in column col(default column 1)\n"); printf (" -d [col] show times as difference from the routine in column col(default column 1)\n"); #else printf (" -r col show times as ratios of the routine in column col\n"); printf (" -d col show times as difference from the routine in column col\n"); #endif printf (" -D show times as difference from previous size shown\n"); printf (" -c show times in CPU cycles\n"); printf (" -C show times in cycles per limb\n"); printf (" -u print resource usage (memory) at end\n"); printf (" -P name output plot files \"name.gnuplot\" and \"name.data\"\n"); printf (" -a <type> use given data: random(default), random2, zeros, aas, ffs, 2fd\n"); printf (" -x, -y, -w, -W <align> specify data alignments, sources and dests\n"); printf (" -o addrs print addresses of data blocks\n"); printf (" colsum=A+B+...+Z Sums the columns A,B,.. upto a max of %d columns\n",SUMMAX); printf (" colfile=col,filename Use the data in column col from file filename\n"); printf ("\n"); printf ("float*routine prefix can be used to multiply a column by a scale factor float.\n\n"); printf ("If both -t and -f are used, it means step by the factor or the step, whichever\n"); printf ("is greater.\n"); printf ("If both -C and -D are used, it means cycles per however many limbs between a\n"); printf ("size and the previous size.\n"); printf ("\n"); printf ("After running with -P, plots can be viewed with Gnuplot or Quickplot.\n"); printf ("\"gnuplot name.gnuplot\" (use \"set logscale xy; replot\" at the prompt for\n"); printf ("a log/log plot).\n"); printf ("\"quickplot -s name.data\" (has interactive zooming, and note -s is important\n"); printf ("when viewing more than one routine, it means same axis scales for all data).\n"); printf ("\n"); printf ("The available routines are as follows.\n"); printf ("\n"); for (i = 0; i < numberof (routine); i++) { if (routine[i].flag & FLAG_R) printf ("\t%s.r\n", routine[i].name); else if (routine[i].flag & FLAG_R_OPTIONAL) printf ("\t%s (optional .r)\n", routine[i].name); else printf ("\t%s\n", routine[i].name); } printf ("\n"); printf ("Routines with a \".r\" need an extra parameter, for example mpn_lshift.6\n"); printf ("r should be in decimal, or use 0xN for hexadecimal.\n"); printf ("\n"); printf ("Special forms for r are \"<N>bits\" for a random N bit number, \"<N>ones\" for\n"); printf ("N one bits, or \"aas\" for 0xAA..AA.\n"); printf ("\n"); printf ("Times for sizes out of the range accepted by a routine are shown as 0.\n"); printf ("The fastest routine at each size is marked with a # (free form output only)\n"); printf ("but columns that are summed are excluded.\n"); printf ("\n"); printf ("%s", speed_time_string); printf ("\n"); printf ("Gnuplot home page http://www.cs.dartmouth.edu/gnuplot_info.html\n"); printf ("Quickplot home page http://www.kachinatech.com/~quickplot\n"); }
void usage (void) { int i; speed_time_init (); printf ("Usage: speed [-options] -s size <routine>...\n"); printf ("Measure the speed of some routines.\n"); printf ("Times are in seconds, accuracy is shown.\n"); printf ("\n"); printf (" -p num set precision as number of time units each routine must run\n"); printf (" -s size[-end][,size[-end]]... sizes to measure\n"); printf (" single sizes or ranges, sep with comma or use multiple -s\n"); printf (" -t step step through sizes by given amount\n"); printf (" -f factor step through sizes by given factor (eg. 1.05)\n"); printf (" -r show times as ratios of the first routine\n"); printf (" -d show times as difference from the first routine\n"); printf (" -D show times as difference from previous size shown\n"); printf (" -c show times in CPU cycles\n"); printf (" -C show times in cycles per limb\n"); printf (" -u print resource usage (memory) at end\n"); printf (" -P name output plot files \"name.gnuplot\" and \"name.data\"\n"); printf (" -a <type> use given data: random(default), random2, zeros, aas, ffs, 2fd\n"); printf (" -x, -y, -w, -W <align> specify data alignments, sources and dests\n"); printf (" -o addrs print addresses of data blocks\n"); printf ("\n"); printf ("If both -t and -f are used, it means step by the factor or the step, whichever\n"); printf ("is greater.\n"); printf ("If both -C and -D are used, it means cycles per however many limbs between a\n"); printf ("size and the previous size.\n"); printf ("\n"); printf ("After running with -P, plots can be viewed with Gnuplot or Quickplot.\n"); printf ("\"gnuplot name.gnuplot\" (use \"set logscale xy; replot\" at the prompt for\n"); printf ("a log/log plot).\n"); printf ("\"quickplot -s name.data\" (has interactive zooming, and note -s is important\n"); printf ("when viewing more than one routine, it means same axis scales for all data).\n"); printf ("\n"); printf ("The available routines are as follows.\n"); printf ("\n"); for (i = 0; i < numberof (routine); i++) { if (routine[i].flag & FLAG_R) printf ("\t%s.r\n", routine[i].name); else if (routine[i].flag & FLAG_R_OPTIONAL) printf ("\t%s (optional .r)\n", routine[i].name); else printf ("\t%s\n", routine[i].name); } printf ("\n"); printf ("Routines with a \".r\" need an extra parameter, for example mpn_lshift.6\n"); printf ("r should be in decimal, or use 0xN for hexadecimal.\n"); printf ("\n"); printf ("Special forms for r are \"<N>bits\" for a random N bit number, \"<N>ones\" for\n"); printf ("N one bits, or \"aas\" for 0xAA..AA.\n"); printf ("\n"); printf ("Times for sizes out of the range accepted by a routine are shown as 0.\n"); printf ("The fastest routine at each size is marked with a # (free form output only).\n"); printf ("\n"); printf ("%s", speed_time_string); printf ("\n"); printf ("Gnuplot home page http://www.gnuplot.info/\n"); printf ("Quickplot home page http://quickplot.sourceforge.net/\n"); }