Skip to content

Instantly share code, notes, and snippets.

@pramsey
Last active April 28, 2021 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramsey/493b2490a8736fd8c00e30efa62e4ec3 to your computer and use it in GitHub Desktop.
Save pramsey/493b2490a8736fd8c00e30efa62e4ec3 to your computer and use it in GitHub Desktop.
/*
cc projtimer.c -I/usr/local/include -L/usr/local/lib -lproj -o projtimer
./projtimer epsg:4326 epsg:4326
./projtimer epsg:4326 epsg:26910
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "proj.h"
static double
time_difference_us(struct timeval start, struct timeval end)
{
int64_t diff_us = (int64_t)(end.tv_usec - start.tv_usec);
if (start.tv_sec == end.tv_sec) {
return (double)diff_us;
}
else {
int64_t diff_s = (int64_t)(end.tv_sec - start.tv_sec);
return (double)(diff_s)*1000000 + (double)(diff_us);
}
}
int main(int argnum, const char** args)
{
int iterations = 1000;
const char *pj_from_str = "epsg:4326";
const char *pj_to_str = "epsg:4326";
struct timeval start, end;
double diff;
if (argnum >= 3 && args[1] && args[2]) {
pj_from_str = args[1];
pj_to_str = args[2];
}
PJ_INFO info = proj_info();
printf("Proj version '%s'\n", info.version);
printf("Using '%s' as from-srid\n", pj_from_str);
printf("Using '%s' as to-srid\n", pj_to_str);
gettimeofday(&start, NULL);
for (int i = 0; i < iterations; i++) {
PJ* projpj = proj_create_crs_to_crs(NULL, pj_from_str, pj_to_str, NULL);
PJ* dpj = proj_destroy(projpj);
}
gettimeofday(&end, NULL);
diff = time_difference_us(start, end);
printf("Ran %d iterations, %g us per iteration\n", iterations, diff/iterations);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment