mirror of
https://gitlab.com/Nils_Kasulke/spectre_project.git
synced 2026-04-04 06:27:26 +00:00
50 lines
967 B
C
50 lines
967 B
C
/*
|
|
* not usable clock() isn't precise enough
|
|
*
|
|
*
|
|
*/
|
|
#include<stdio.h>
|
|
#include <stdint.h>
|
|
#include<time.h>
|
|
#include<stdlib.h>
|
|
|
|
void usage_and_exit();
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if(argc != 4) usage_and_exit();
|
|
|
|
uint64_t t0, t1;
|
|
int a, b;
|
|
sscanf(argv[2], "%d", &a);
|
|
sscanf(argv[3], "%d", &b);
|
|
if(argv[1][0] == 'd') {
|
|
double out;
|
|
t0 = (uint64_t) clock();
|
|
out = (double) a / b;
|
|
t1 = (uint64_t) clock();
|
|
printf("out = %lf\n", out);
|
|
} else if(argv[1][0] == 'f') {
|
|
float out;
|
|
t0 = (uint64_t) clock();
|
|
out = (float) a / b;
|
|
t1 = (uint64_t) clock();
|
|
printf("out = %f\n", out);
|
|
} else if(argv[1][0] == 'i') {
|
|
int out;
|
|
t0 = (uint64_t) clock();
|
|
out = a / b;
|
|
t1 = (uint64_t) clock();
|
|
printf("out = %d\n", out);
|
|
} else {
|
|
usage_and_exit();
|
|
}
|
|
printf("clocks = %lu\n", t1 - t0);
|
|
}
|
|
void usage_and_exit() {
|
|
printf("<prog> <i|f|d> <a> <b>\n");
|
|
printf("i = integer\n");
|
|
printf("f = float\n");
|
|
printf("d = double\n");
|
|
exit(1);
|
|
}
|