Skip to content

Commit

Permalink
Get PoW execution time and calculate hash rate
Browse files Browse the repository at this point in the history
  • Loading branch information
marktwtn committed Sep 26, 2018
1 parent 93ebb77 commit edd5fc8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pow_avx.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ bool PowAVX(void *pow_ctx)
bool res = true;
Trits_t *nonce_trit = NULL;
Trytes_t *tx_tryte = NULL, *nonce_tryte = NULL;
time_t start_time, end_time;

/* Initialize the context */
PoW_AVX_Context *ctx = (PoW_AVX_Context *) pow_ctx;
Expand All @@ -558,6 +559,7 @@ bool PowAVX(void *pow_ctx)
goto fail;
}

time(&start_time);
/* Prepare arguments for pthread */
for (int i = 0; i < ctx->num_threads; i++) {
pitem[i].mid = c_state;
Expand All @@ -577,6 +579,8 @@ bool PowAVX(void *pow_ctx)
completedIndex = i;
ctx->pow_info->hash_count += (uint64_t) (pitem[i].ret >= 0 ? pitem[i].ret : -pitem[i].ret + 1);
}
time(&end_time);
ctx->pow_info->time = difftime(end_time, start_time);

nonce_trit = initTrits(nonce_array[completedIndex], NonceTrinarySize);
if (!nonce_trit) {
Expand Down
4 changes: 4 additions & 0 deletions src/pow_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ bool PowC(void *pow_ctx)
bool res = true;
Trits_t *nonce_trit = NULL;
Trytes_t *tx_tryte = NULL, *nonce_tryte = NULL;
time_t start_time, end_time;

/* Initialize the context */
PoW_C_Context *ctx = (PoW_C_Context *) pow_ctx;
Expand All @@ -319,6 +320,7 @@ bool PowC(void *pow_ctx)
goto fail;
}

time(&start_time);
/* Prepare arguments for pthread */
for (int i = 0; i < ctx->num_threads; i++) {
pitem[i].mid = c_state;
Expand All @@ -338,6 +340,8 @@ bool PowC(void *pow_ctx)
completedIndex = i;
ctx->pow_info->hash_count += (uint64_t) (pitem[i].ret >= 0 ? pitem[i].ret : -pitem[i].ret + 1);
}
time(&end_time);
ctx->pow_info->time = difftime(end_time, start_time);

nonce_trit = initTrits(nonce_array[completedIndex], NonceTrinarySize);
if (!nonce_trit) {
Expand Down
4 changes: 4 additions & 0 deletions src/pow_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ bool PowCL(void *pow_ctx)
int8_t *c_state = NULL, *pow_result = NULL;
Trits_t *tx_trit = NULL;
Trytes_t *tx_tryte = NULL, *res_tryte = NULL;
time_t start_time, end_time;

PoW_CL_Context *ctx = (PoW_CL_Context *) pow_ctx;

Expand All @@ -215,7 +216,10 @@ bool PowCL(void *pow_ctx)
goto fail;
}

time(&start_time);
pow_result = pwork(c_state, ctx->mwm, ctx->clctx);
time(&end_time);
ctx->pow_info->time = difftime(end_time, start_time);
if (!pow_result) {
res = false;
goto fail;
Expand Down
1 change: 1 addition & 0 deletions src/pow_fpga_accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static bool PoWFPGAAccel(void *pow_ctx)

Trytes_t *object_tryte = NULL, nonce_tryte = NULL;
Trits_t *object_trit = NULL, *object_nonce_trit = NULL;
time_t start_time, end_time;

object_tryte =
initTrytes(ctx->input_trytes, (transactionTrinarySize) / 3);
Expand Down
4 changes: 4 additions & 0 deletions src/pow_sse.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ bool PowSSE(void *pow_ctx)
bool res = true;
Trits_t *nonce_trit = NULL;
Trytes_t *tx_tryte = NULL, *nonce_tryte = NULL;
time_t start_time, end_time;

/* Initialize the context */
PoW_SSE_Context *ctx = (PoW_SSE_Context *) pow_ctx;
Expand All @@ -336,6 +337,7 @@ bool PowSSE(void *pow_ctx)
goto fail;
}

time(&start_time);
/* Prepare arguments for pthread */
for (int i = 0; i < ctx->num_threads; i++) {
pitem[i].mid = c_state;
Expand All @@ -355,6 +357,8 @@ bool PowSSE(void *pow_ctx)
completedIndex = i;
ctx->pow_info->hash_count += (uint64_t) (pitem[i].ret >= 0 ? pitem[i].ret : -pitem[i].ret + 1);
}
time(&end_time);
ctx->pow_info->time = difftime(end_time, start_time);

nonce_trit = initTrits(nonce_array[completedIndex], NonceTrinarySize);
if (!nonce_trit) {
Expand Down
2 changes: 2 additions & 0 deletions tests/test-pow.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ int main()
#if defined(ENABLE_STAT)
PoW_Info *info = (PoW_Info *) getPoWInfo(PoW_Context_ptr, pow_ctx);
printf("Hash count: %"PRIu64"\n", info->hash_count);
printf("PoW execution time: %.0lf sec\n", info->time);
printf("Hash rate: %.3lf per sec\n", info->hash_count / info->time);
#endif
freePoWContext(PoW_Context_ptr, pow_ctx);
destroyImplContext(PoW_Context_ptr);
Expand Down

0 comments on commit edd5fc8

Please sign in to comment.