~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to benchmarks/multi/harness.c

  • Committer: Michael Hope
  • Date: 2010-08-30 23:37:42 UTC
  • Revision ID: michael.hope@linaro.org-20100830233742-sgozrcd69kh00dvh
Pulled the raw throughput harness out

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
#include <sys/time.h>
 
3
#include <stdint.h>
 
4
#include <stdlib.h>
 
5
#include <stdio.h>
 
6
#include <stdbool.h>
 
7
 
 
8
static double now()
 
9
{
 
10
  struct timeval tv;
 
11
 
 
12
  gettimeofday(&tv, NULL);
 
13
 
 
14
  return tv.tv_sec + tv.tv_usec * 1e-6;
 
15
}
 
16
 
 
17
static int get_arg(int argc, char **argv, int idx, int fallback)
 
18
{
 
19
  if (argc > idx)
 
20
    {
 
21
      return atoi(argv[idx]);
 
22
    }
 
23
  else
 
24
    {
 
25
      return fallback;
 
26
    }
 
27
}
 
28
 
 
29
static void empty(volatile char *against)
 
30
{
 
31
  /* We know that there's a 16 k cache with 64 byte lines giving
 
32
     a total of 256 lines.  Read randomly from 256*5 places should
 
33
     flush everything */
 
34
  int offset = (1024 - 256)*1024;
 
35
 
 
36
  for (int i = offset; i < offset + 16*1024*3; i += 64)
 
37
    {
 
38
      against[i];
 
39
    }
 
40
}
 
41
 
 
42
static void __attribute__((noinline)) xmemcpy(char *dest, char *src, size_t n)
 
43
{
 
44
  memcpy(dest, src, n);
 
45
}
 
46
 
 
47
static void __attribute__((noinline)) xstrcpy(char *dest, char *src)
 
48
{
 
49
  strcpy(dest, src);
 
50
}
 
51
 
 
52
static void __attribute__((noinline)) xmemset(void *dest, int c, size_t n)
 
53
{
 
54
  memset(dest, c, n);
 
55
}
 
56
 
 
57
int main(int argc, char **argv)
 
58
{
 
59
  char *src = calloc(1024, 1024);
 
60
  char *dest = calloc(1024, 1024);
 
61
 
 
62
  srandom(1539);
 
63
 
 
64
  for (int i = 0; i < 16*1024; i++)
 
65
    {
 
66
      src[i] = (char)random() | 1;
 
67
    }
 
68
 
 
69
  int count = get_arg(argc, argv, 1, 31);
 
70
  int loops = get_arg(argc, argv, 2, 10000000);
 
71
  int flush = get_arg(argc, argv, 3, 0);
 
72
 
 
73
  src[count] = 0;
 
74
 
 
75
  double start = now();
 
76
 
 
77
  for (int i = 0; i < loops; i++)
 
78
    {
 
79
#if defined(WITH_MEMCPY)
 
80
      xmemcpy(dest, src, count);
 
81
#elif defined(WITH_STRCPY)
 
82
      xstrcpy(dest, src);
 
83
#elif defined(WITH_MEMSET)
 
84
      xmemset(src, 0, count);
 
85
#else
 
86
#error
 
87
#endif
 
88
 
 
89
      if (flush != 0)
 
90
        {
 
91
          empty(dest);
 
92
        }
 
93
    }
 
94
 
 
95
  double end = now();
 
96
  double elapsed = end - start;
 
97
 
 
98
  printf("%.3f for %u loops of %u bytes.  %.3f MB/s\n", elapsed, loops, count, (double)loops*count/elapsed/(1024*1024));
 
99
 
 
100
  return 0;
 
101
}
 
102