Door database problemen is de uitgebreide uitleg verloren gegaan (
), maar hier is de volledig becommentariseerde code van een benchmarksysteem dat zich niets aantrekt van task switches of thread priorities 
code:
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
| // ------------------------------------------------------------------------
// IdiotProof Benchmark Code
// Written by Curry, original idea from OiSyN
//
// Benchmarks are accurate no matter what thread priority since time
// elapsed is taken from kernel thread monitoring data
// ------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <conio.h>
// ------------------------------------------------------------------------
// Helper macros
// ------------------------------------------------------------------------
// Use this macro at the beginning of the function to declare local
// variables used by the benchmark. 10 million iterations gives a fault
// of max. 1 procent
#define MPrepareBenchmark(p_Iterations) \
LARGE_INTEGER l_Before, l_After; \
FILETIME l_CreationTime, l_ExitTime, l_KernelTime; \
int l_Index; \
HANDLE l_ThreadHandle = GetCurrentThread(); \
const int c_Iterations = (p_Iterations)
// The MBeginBenchmark macro initializes loop and prints the method name
#define MBeginBenchmark(p_Name) printf("Method '" #p_Name "'"); \
GetThreadTimes(l_ThreadHandle, &l_CreationTime, &l_ExitTime, \
&l_KernelTime, (LPFILETIME)&l_Before); \
for(l_Index = 0; l_Index != c_Iterations; l_Index++) {
// The MEndBenchmark macro finalizes the loop and prints time results
#define MEndBenchmark } \
GetThreadTimes(l_ThreadHandle, &l_CreationTime, &l_ExitTime, \
&l_KernelTime, (LPFILETIME)&l_After); \
printf(" took %d milliseconds\n", \
(l_After.QuadPart - l_Before.QuadPart) / 10000)
// ------------------------------------------------------------------------
// Main program
// ------------------------------------------------------------------------
int main()
{
// Define benchmark code
MPrepareBenchmark(10000000);
// Following benchmarks were taken from a recent thread on GoT where the
// benchmarking discussion first arose
// Osiris' version
MBeginBenchmark(Osiris);
char Msg[] = "Blablabla";
for(unsigned int i = 0; i != strlen(Msg); i++)
if(Msg[i] == 'a')
Msg[i] = 'c';
MEndBenchmark;
// Curry's version
MBeginBenchmark(Curry684);
char Msg[] = "Blablabla";
for(char *Pointer = Msg; *Pointer; Pointer++)
if(*Pointer == 'a')
*Pointer = 'c';
MEndBenchmark;
// Beelzebubu's version
MBeginBenchmark(Beelzebubu);
char Msg[] = "Blablabla";
for(int i=0;Msg[i];i++)
if(Msg[i]=='a')
Msg[i]='c';
MEndBenchmark;
// Sponz version
MBeginBenchmark(Sponz);
char Msg[] = "Blablabla";
char *p = Msg;
while(p = strchr(p,'a'))
*p='c';
MEndBenchmark;
// Oisyn's version
MBeginBenchmark(Oisyn);
char Msg[] = "Blablabla";
char* Strptr = Msg;
do
{
if(*Strptr == 'a')
*Strptr = 'c';
} while (*Strptr++);
MEndBenchmark;
// Wait for keypress before exit
printf("\nPress any key to exit...");
while(!getch());
return 0;
}
// ------------------------------------------------------------------------ |