diff options
| author | dam <dam@gudinoff> | 2023-07-05 21:13:21 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-07-05 21:13:21 +0100 |
| commit | 108e59b2b649caf3e995a14a2aa5d59f5d916f37 (patch) | |
| tree | e6586151f153f1b96212627b722dc5de012d1372 /Math_Test.jai | |
| parent | d490fd25f4c7bd8988a4e4215a4dacceeebc36ee (diff) | |
| download | task-time-tracker-108e59b2b649caf3e995a14a2aa5d59f5d916f37.tar.zst task-time-tracker-108e59b2b649caf3e995a14a2aa5d59f5d916f37.zip | |
Finalized add, sub, and mul.
Diffstat (limited to 'Math_Test.jai')
| -rw-r--r-- | Math_Test.jai | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/Math_Test.jai b/Math_Test.jai index bd9990b..5fe87c5 100644 --- a/Math_Test.jai +++ b/Math_Test.jai @@ -8,10 +8,10 @@ #load "Math_Ext.jai"; main :: () { - + write_strings( "#=======================#\n", - "# Unit tests #\n" + "# Basic tests #\n" ); test_op :: (operation: string, x: $Tx, y: $Ty, result: $Tr, type: Type, saturated: bool, remainder: Tr = 0) -> errors_found: int #expand { @@ -162,12 +162,22 @@ main :: () { "#=======================#\n", "# Benchmarks #\n" ); - + #import "Random"; + performance_test :: ($operation: string, $type: Type, print_result: bool = true) -> ops_per_us_gen: float, ops_per_us_asm: float { - NUM_TESTS :: 5000; - DATA_SIZE_BITS :: 64*1024*8/2; + #if type == u8 { MIN :: 0; MAX :: U8_MAX; } + #if type == u16 { MIN :: 0; MAX :: U16_MAX; } + #if type == u32 { MIN :: 0; MAX :: U32_MAX; } + #if type == u64 { MIN :: 0; MAX :: U64_MAX; } + #if type == s8 { MIN :: S8_MIN; MAX :: S8_MAX; } + #if type == s16 { MIN :: S16_MIN; MAX :: S16_MAX; } + #if type == s32 { MIN :: S32_MIN; MAX :: S32_MAX; } + #if type == s64 { MIN :: S64_MIN; MAX :: S64_MAX; } + + NUM_TESTS :: 50000; + DATA_SIZE_BITS :: 64*1024*8; #if type == s8 || type == u8 then DATA_SIZE :: DATA_SIZE_BITS/8; else #if type == s16 || type == u16 then @@ -176,27 +186,15 @@ main :: () { DATA_SIZE :: DATA_SIZE_BITS/32; else #if type == s64 || type == u64 then DATA_SIZE :: DATA_SIZE_BITS/64; - + best_gen := 0.0; best_asm := 0.0; - - numbers_xgen: [..] type; - numbers_ygen: [..] type; - numbers_xasm: [..] type; - numbers_yasm: [..] type; - array_reserve(*numbers_xgen, DATA_SIZE); - array_reserve(*numbers_ygen, DATA_SIZE); - array_reserve(*numbers_xasm, DATA_SIZE); - array_reserve(*numbers_yasm, DATA_SIZE); - - #if type == u8 { MIN :: 0; MAX :: U8_MAX; } - #if type == u16 { MIN :: 0; MAX :: U16_MAX; } - #if type == u32 { MIN :: 0; MAX :: U32_MAX; } - #if type == u64 { MIN :: 0; MAX :: U64_MAX; } - #if type == s8 { MIN :: S8_MIN; MAX :: S8_MAX; } - #if type == s16 { MIN :: S16_MIN; MAX :: S16_MAX; } - #if type == s32 { MIN :: S32_MIN; MAX :: S32_MAX; } - #if type == s64 { MIN :: S64_MIN; MAX :: S64_MAX; } + numbers_x: [..] type; + numbers_y: [..] type; + array_reserve(*numbers_x, DATA_SIZE); + array_reserve(*numbers_y, DATA_SIZE); + + random_seed(cast(u64)to_nanoseconds(current_time_monotonic())); for 0..DATA_SIZE-1 { x := cast(type) random_get_within_range(xx MIN, xx MAX); @@ -204,27 +202,25 @@ main :: () { if y == 0 && operation == "div" { y = 1; } - array_add(*numbers_xgen, x); - array_add(*numbers_ygen, y); - array_add(*numbers_xasm, x); - array_add(*numbers_yasm, y); + array_add(*numbers_x, x); + array_add(*numbers_y, y); } for 0..NUM_TESTS-1 { - + r_gen: type = 0; r_asm: type = 0; time_gen := current_time_monotonic(); - for 0..DATA_SIZE-1 #insert #run replace("r_gen ^= OP(numbers_xgen[it], numbers_ygen[it], true);", "OP", operation); + for idx: 0..DATA_SIZE-1 #insert #run replace("r_gen ^= OP(numbers_x[idx], numbers_y[idx], true);", "OP", operation); time_gen = current_time_monotonic() - time_gen; - + time_asm := current_time_monotonic(); - for 0..DATA_SIZE-1 #insert #run replace("r_asm ^= OP(numbers_xasm[it], numbers_yasm[it]);", "OP", operation); + for idx: 0..DATA_SIZE-1 #insert #run replace("r_asm ^= OP(numbers_x[idx], numbers_y[idx]);", "OP", operation); time_asm = current_time_monotonic() - time_asm; assert(r_gen == r_asm); - + perf_gen := cast(float)DATA_SIZE/cast(float)to_nanoseconds(time_gen); perf_asm := cast(float)DATA_SIZE/cast(float)to_nanoseconds(time_asm); best_gen = max(best_gen, perf_gen); @@ -236,7 +232,7 @@ main :: () { ff := *context.print_style.default_format_float; ff.zero_removal = .NO; ff.width = 7; - ff.trailing_width = 3; + ff.trailing_width = 2; fi := *context.print_style.default_format_int; fi.minimum_digits = 3; |
