Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active December 27, 2016 20:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/c531a4801a84e2c06af11588ce29068e to your computer and use it in GitHub Desktop.
Save mfikes/c531a4801a84e2c06af11588ce29068e to your computer and use it in GitHub Desktop.
Source for C and ClojureScript comparison

Source for this comparison of C and ClojureScript perf.

C source:

#include <stdio.h>
#include <mach/mach.h>
#include <mach/mach_time.h>

int main() {

  double acc, n = 0;

  uint64_t begin = mach_absolute_time();

  while ( n < 1e7 ) {
    acc += n++;
  }

  uint64_t end = mach_absolute_time();

  printf("%.0f\n", acc);

  mach_timebase_info_data_t sTimebaseInfo;
  mach_timebase_info(&sTimebaseInfo);

  double millis = (1e-6 * (end-begin) * sTimebaseInfo.numer) / sTimebaseInfo.denom;

  printf("Elapsed time: %f millis\n", millis);

}

ClojureScript source:

(time (apply + (range 1e7)))

The comparison is done using clang and Planck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment