forked from logicchains/ArrayAccessBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.c
69 lines (56 loc) · 1.4 KB
/
C.c
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
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define NUM_RECORDS (50 * 1000 * 444)
struct CMemoryTrade {
long TradeId; long ClientId; int VenueCode; int InstrumentCode; long Price; long Quantity; char Side;
};
struct CMemoryTrade trades[NUM_RECORDS];
void initTrades() {
for (long i = 0; i < NUM_RECORDS; i++) {
struct CMemoryTrade *trade = &(trades[i]);
trade->TradeId = i;
trade->ClientId = 1;
trade->VenueCode = 123;
trade->InstrumentCode = 321;
trade->Price = i;
trade->Quantity = i;
if ((i&1) == 0) {
trade->Side = 'B';
} else {
trade->Side = 'S';
}
}
}
double getTime(){
struct timespec spec;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec);
double s = spec.tv_sec;
double ms = spec.tv_nsec;
return (s*1000 + ms / 1000000);
}
void perfRun(int runNum) {
double startT = getTime();
initTrades();
long buyCost = 0;
long sellCost = 0;
for (long i = 0; i < NUM_RECORDS; i++) {
struct CMemoryTrade *trade = &(trades[i]);
if (trade->Side == 'B') {
buyCost += trade->Price * trade->Quantity;
} else {
sellCost += trade->Price * trade->Quantity;
}
}
double endT = getTime();
double duration = endT - startT;
printf("%d - duration %d ms\n", runNum, (int)duration);
printf("buyCost = %ld sellCost = %ld\n", buyCost, sellCost);
}
int main() {
for (int i = 0; i < 5; i++) {
perfRun(i);
}
}