-
-
Save logicchains/9032441 to your computer and use it in GitHub Desktop.
TestDMemoryLayout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.datetime; | |
enum { | |
NUM_RECORDS = 50 * 1000 * 444 | |
} | |
DMemoryTrade[NUM_RECORDS] trades = void; | |
struct DMemoryTrade { | |
long TradeId; | |
long ClientId; | |
int VenueCode; | |
int InstrumentCode; | |
long Price; | |
long Quantity; | |
byte Side; | |
}; | |
void main() { | |
for (auto i = 0; i < NUM_RECORDS; i++ ){ | |
DMemoryTrade trade; | |
trade.TradeId = 0; | |
trade.ClientId = 0; | |
trade.VenueCode = 0; | |
trade.InstrumentCode = 0; | |
trade.Price = 0; | |
trade.Quantity = 0; | |
trade.Side = 'A'; | |
trades[i] = trade; | |
} | |
for (auto i = 0; i < 5; i++ ){ | |
perfRun(i); | |
} | |
} | |
void perfRun(int runNum ) { | |
auto start = Clock.currTime(); | |
initTrades(); | |
long buyCost = 0; | |
long sellCost = 0; | |
for (auto i = 0; i < NUM_RECORDS; i++ ){ | |
auto trade = &(trades[i]); | |
if (trade.Side == 'B') { | |
buyCost += trade.Price * trade.Quantity; | |
} else { | |
sellCost += trade.Price * trade.Quantity; | |
} | |
} | |
auto endT = Clock.currTime(); | |
long duration = (endT-start).fracSec.msecs + (endT-start).seconds * 1000; | |
printf("%d - duration %d ms\n", runNum, duration); | |
printf("buyCost = %d sellCost = %d\n", buyCost, sellCost); | |
} | |
void initTrades() { | |
for (auto i = 0; i < NUM_RECORDS; i++) { | |
auto 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'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment