Skip to content

Commit

Permalink
Yo, someone explain how deleting this has slowed down my app
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumbub committed Oct 14, 2021
1 parent 33068c0 commit e79b2f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
10 changes: 5 additions & 5 deletions results/benchmark.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
------------------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------------------------
BM_NextBoard/iterations:3000/process_time/real_time 4.01 ms 15.4 ms 3000
BM_RenderBoard/process_time/real_time 8.66 ms 8.58 ms 72
Renders per second: 31.1941
Boards per second: 210.061
BM_Main/iterations:1/repeats:1/process_time/real_time 9.52 s 34.6 s 1
BM_NextBoard/iterations:3000/process_time/real_time 4.19 ms 16.1 ms 3000
BM_RenderBoard/process_time/real_time 8.32 ms 8.09 ms 77
Renders per second: 31.1944
Boards per second: 201.254
BM_Main/iterations:1/repeats:1/process_time/real_time 9.94 s 36.2 s 1
10 changes: 0 additions & 10 deletions src/board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ using Cell = uint;
struct BoardMeta {
Cell* input = nullptr;
Cell* output = nullptr;
Cell* render = nullptr;

uint width;
uint height;

Cell* raw = nullptr;
Cell* rawRender = nullptr;

uint threads = PROBABLY_OPTIMAL_THREAD_COUNT;
uint microsPerRender = 32000; // 30fps
Expand All @@ -34,9 +32,6 @@ struct BoardMeta {
if (this->width * this->height != width * height) {
delete[] raw;
raw = nullptr;

delete[] rawRender;
rawRender = nullptr;
}

this->width = width;
Expand All @@ -52,10 +47,6 @@ struct BoardMeta {
input = &raw[0];
output = &raw[size];
}
if (rawRender == nullptr) {
rawRender = new Cell[size];
render = &rawRender[0];
}
}

BoardMeta(const uint& width, const uint& height) {
Expand All @@ -66,7 +57,6 @@ struct BoardMeta {

~BoardMeta() {
delete[] raw;
delete[] rawRender;
}

private:
Expand Down
8 changes: 4 additions & 4 deletions src/board/generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ void benchmarkBoard(BoardMeta& board, unsigned int width, unsigned int height) {
const unsigned int i = y * width + x;
if (y > height / 2) {
if (x < width / 2)
board.input[i] = board.render[i] = rand() % 2 ? ALIVE : DEAD;
board.input[i] = rand() % 2 ? ALIVE : DEAD;
if (x >= width / 2)
board.input[i] = board.render[i] = (x / 8) % 2 != (y / 8) % 2 ? ALIVE : DEAD;
board.input[i] = (x / 8) % 2 != (y / 8) % 2 ? ALIVE : DEAD;
} else {
const unsigned int breederMarginY = (height / 2 - BREEDER_HEIGHT) / 2;
const unsigned int breederY = y - breederMarginY;
if (breederY > 0 && breederY < BREEDER_HEIGHT && x < BREEDER_WIDTH) {
board.input[i] = board.render[i] = BREEDER[breederY][x] ? ALIVE : DEAD;
board.input[i] = BREEDER[breederY][x] ? ALIVE : DEAD;
} else {
board.input[i] = board.render[i] = DEAD;
board.input[i] = DEAD;
}
}
}
Expand Down

0 comments on commit e79b2f7

Please sign in to comment.