From 5a9aeee41075bdc503d1d5c58f7f569e78ea8313 Mon Sep 17 00:00:00 2001 From: marktwtn Date: Tue, 25 Sep 2018 21:34:49 +0800 Subject: [PATCH] Get PoW execution time and calculate hash rate --- src/pow_avx.c | 4 ++++ src/pow_c.c | 4 ++++ src/pow_cl.c | 4 ++++ src/pow_fpga_accel.c | 1 + src/pow_sse.c | 4 ++++ tests/test-pow.c | 2 ++ 6 files changed, 19 insertions(+) diff --git a/src/pow_avx.c b/src/pow_avx.c index 8f3d531..827c204 100644 --- a/src/pow_avx.c +++ b/src/pow_avx.c @@ -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; @@ -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; @@ -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) { diff --git a/src/pow_c.c b/src/pow_c.c index 7fcecd7..7f008e8 100644 --- a/src/pow_c.c +++ b/src/pow_c.c @@ -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; @@ -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; @@ -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) { diff --git a/src/pow_cl.c b/src/pow_cl.c index bc87a51..eb04138 100644 --- a/src/pow_cl.c +++ b/src/pow_cl.c @@ -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; @@ -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; diff --git a/src/pow_fpga_accel.c b/src/pow_fpga_accel.c index a971081..912e453 100644 --- a/src/pow_fpga_accel.c +++ b/src/pow_fpga_accel.c @@ -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); diff --git a/src/pow_sse.c b/src/pow_sse.c index df3b865..a3daa46 100644 --- a/src/pow_sse.c +++ b/src/pow_sse.c @@ -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; @@ -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; @@ -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) { diff --git a/tests/test-pow.c b/tests/test-pow.c index 66fa41a..6fee82c 100644 --- a/tests/test-pow.c +++ b/tests/test-pow.c @@ -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);