Created
March 2, 2022 00:40
-
-
Save wesgarland/682ed83db6a3f60b6fcb543a1878ae07 to your computer and use it in GitHub Desktop.
C analogue of parse-float.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CFLAGS=-O2 make parse-float */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main (int argc, const char *argv[]) | |
{ | |
const char *buf = "0.45494253843119004"; | |
int i; | |
float f; | |
clock_t start, stop; | |
f = strtod(buf, (char **)NULL); | |
f = strtod(buf, (char **)NULL); | |
f = strtod(buf, (char **)NULL); | |
start = clock(); | |
for (i=0; i < 1000000; i++) | |
f = strtod(buf, (char **)NULL); | |
stop = clock(); | |
printf("%g %lu\n", f, stop-start); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment