Skip to content

Instantly share code, notes, and snippets.

@wesgarland
Created March 2, 2022 00:40
Show Gist options
  • Save wesgarland/682ed83db6a3f60b6fcb543a1878ae07 to your computer and use it in GitHub Desktop.
Save wesgarland/682ed83db6a3f60b6fcb543a1878ae07 to your computer and use it in GitHub Desktop.
C analogue of parse-float.js
/* 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