All pastes #766835 Raw Edit

Something

public text v1 · immutable
·published 2007-11-09 05:22 UTC
rendered paste body
#include <stdio.h>
#include <sys/time.h>

int get_ms()
{
  struct timeval tv;
  struct timezone tzp;
  return (tv.tv_sec / 1000) + (tv.tv_usec * 1000);
}

#define dup_macro2(name)                                                      \
  name                                                                        \
  name                                                                        \

#define dup_macro4(name)                                                      \
  dup_macro2(dup_macro2(name))                                                \

#define dup_macro16(name)                                                     \
  dup_macro4(dup_macro4(name))                                                \

#define dup_macro256(name)                                                    \
  dup_macro16(dup_macro16(name))                                              \

#define dup_macro2048(name)                                                   \
  dup_macro2(dup_macro4(dup_macro256(name)))                                  \

#define arm_add                                                               \
  "add r0, r0, r0\n"                                                          \

int main()
{
  int start_time, total_time;
  int i;
  const int iterations = 65536;
  const int total_adds = 65536 * 2048;

  start_time = get_ms();

  for(i = iterations; i >= 0; i--)
  {
    asm
    (
      dup_macro2048(arm_add)
      : : "r0";
    );
  }

  total_time = get_ms() - start_time;

  printf("benchmark took %d ms, roughly %d million cycles per second\n",
   total_time, (total_iterations / total_time) / 1000);

  return 0;
}