summaryrefslogtreecommitdiff
path: root/legacy/evil/src/bin/test_memcpy.c
blob: ea2bcacba07e94f3f46ed2d40fc5506d194a3374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

#include "suite.h"
#include "test_memcpy.h"


typedef void *(*memcpy_decl)(void *dest, const void *src, size_t n);

void *memcpy_glibc(void *dest, const void *src, size_t n);


extern unsigned char *buf1;
extern unsigned char *buf2;
extern size_t         page_size;


static void
test_memcpy_test_run(memcpy_decl fct, char *dst, const char *src, size_t len)
{
   double start;
   double end;
   double best;
   int    i;

   best = 1000000000.0;

   for (i = 0; i < 32; ++i)
     {
        double time;

        suite_time_start();
        fct(dst, src, len);
        suite_time_stop();
        time = suite_time_get();
        if (time < best) best = time;
     }

   printf ("  %e", best);
}

static void
test_memcpy_tests_run(size_t align1, size_t align2, size_t len)
{
   size_t i, j;
   char *s1, *s2;

   printf ("running test..\n");

/*    align1 &= 63; */
/*    if (align1 + len >= page_size) */
/*      return; */

/*    align2 &= 63; */
/*    if (align2 + len >= page_size) */
/*      return; */

   s1 = (char *) (buf1 + align1);
   s2 = (char *) (buf2 + align2);

   for (i = 0, j = 1; i < len; i++, j += 23)
     s1[i] = j;

   printf ("length: %6d, align %2d/%2d:", (int)len, align1, align2);

   test_memcpy_test_run(memcpy, s2, s1, len);
   test_memcpy_test_run(memcpy_glibc, s2, s1, len);

   printf ("\n");
}

void
test_memcpy(void)
{
   size_t i;

/*   for (i = 0; i < 18; ++i) */
/*     { */
/*       test_memcpy_tests_run(0, 0, 1 << i); */
/*       test_memcpy_tests_run(i, 0, 1 << i); */
/*       test_memcpy_tests_run(0, i, 1 << i); */
/*       test_memcpy_tests_run(i, i, 1 << i); */
/*     } */

/*   for (i = 0; i < 32; ++i) */
/*     { */
/*       test_memcpy_tests_run(0, 0, i); */
/*       test_memcpy_tests_run(i, 0, i); */
/*       test_memcpy_tests_run(0, i, i); */
/*       test_memcpy_tests_run(i, i, i); */
/*     } */

/*   for (i = 3; i < 32; ++i) */
/*     { */
/*       if ((i & (i - 1)) == 0) */
/* 	continue; */
/*       test_memcpy_tests_run(0, 0, 16 * i); */
/*       test_memcpy_tests_run(i, 0, 16 * i); */
/*       test_memcpy_tests_run(0, i, 16 * i); */
/*       test_memcpy_tests_run(i, i, 16 * i); */
/*     } */

  test_memcpy_tests_run(0, 0, getpagesize ());
  test_memcpy_tests_run(0, 0, 2 * getpagesize ());
  test_memcpy_tests_run(0, 0, 4 * getpagesize ());
  test_memcpy_tests_run(0, 0, 8 * getpagesize ());
}