aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-07-01 01:39:28 +0100
committerdam <dam@gudinoff>2023-07-01 01:39:28 +0100
commitcd7c80fdcc98f38527e7e35488c064af169bd7c0 (patch)
treeaf9b5a4b3b7b068b89ec93c390e5da518b492483
parent0ebbaf1c570e0c5512a580d5f9e240baf8e221fa (diff)
downloadtask-time-tracker-cd7c80fdcc98f38527e7e35488c064af169bd7c0.tar.zst
task-time-tracker-cd7c80fdcc98f38527e7e35488c064af169bd7c0.zip
Improving tests.
-rw-r--r--Math_Test.jai56
1 files changed, 36 insertions, 20 deletions
diff --git a/Math_Test.jai b/Math_Test.jai
index 781afa0..d216fd2 100644
--- a/Math_Test.jai
+++ b/Math_Test.jai
@@ -4,6 +4,7 @@
#import "Basic";
#import "Compiler";
#import "Math";
+#import "String";
#load "Math_Ext.jai";
main :: () {
@@ -16,7 +17,6 @@ main :: () {
test_op :: (operation: string, x: $Tx, y: $Ty, result: $Tr, type: Type, saturated: bool, remainder: Tr = 0) -> errors_found: int #expand {
print_test_call :: (operation: string) -> string {
- #import "String";
str: string = ---;
if operation != "div" {
TEST_CALL :: #string DONE
@@ -166,17 +166,31 @@ main :: () {
#import "Random";
performance_test :: ($operation: string, $type: Type, print_result: bool = true) -> ops_per_us_gen: float, ops_per_us_asm: float {
- NUM_TESTS :: 500;
- SIZE_DATA :: 12000; // Keep it below cache size.
+ NUM_TESTS :: 5000;
+ // DATA_SIZE :: 32768;
+ DATA_SIZE_BITS :: 96*1024*8;
+ #if type == s8 || type == u8 then
+ DATA_SIZE :: DATA_SIZE_BITS/3/8;
+ else #if type == s16 || type == u16 then
+ DATA_SIZE :: DATA_SIZE_BITS/3/16;
+ else #if type == s32 || type == u32 then
+ DATA_SIZE :: DATA_SIZE_BITS/3/32;
+ else #if type == s64 || type == u64 then
+ DATA_SIZE :: DATA_SIZE_BITS/3/64;
+
best_gen := 0.0;
best_asm := 0.0;
- numbers_x: [..] type;
- numbers_y: [..] type;
- numbers_zgen: [SIZE_DATA] type;
- numbers_zasm: [SIZE_DATA] type;
- array_reserve(*numbers_x, SIZE_DATA);
- array_reserve(*numbers_y, SIZE_DATA);
+ numbers_xgen: [..] type;
+ numbers_ygen: [..] type;
+ numbers_zgen: [DATA_SIZE] type;
+ numbers_xasm: [..] type;
+ numbers_yasm: [..] type;
+ numbers_zasm: [DATA_SIZE] 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; }
@@ -187,37 +201,39 @@ main :: () {
#if type == s32 { MIN :: S32_MIN; MAX :: S32_MAX; }
#if type == s64 { MIN :: S64_MIN; MAX :: S64_MAX; }
- for 0..SIZE_DATA-1 {
+ for 0..DATA_SIZE-1 {
x := cast(type) random_get_within_range(xx MIN, xx MAX);
y := cast(type) random_get_within_range(xx MIN, xx MAX);
if y == 0 && operation == "div" {
y = 1;
}
- array_add(*numbers_x, x);
- array_add(*numbers_y, y);
+ array_add(*numbers_xgen, x);
+ array_add(*numbers_ygen, y);
+ array_add(*numbers_xasm, x);
+ array_add(*numbers_yasm, y);
}
-
+
for 0..NUM_TESTS-1 {
-
+
time_gen := current_time_monotonic();
- for 0..SIZE_DATA-1 #insert #run replace("numbers_zgen[it] = OP(numbers_x[it], numbers_y[it], true);", "OP", operation);
+ for 0..DATA_SIZE-1 #insert #run replace("numbers_zgen[it] = OP(numbers_xgen[it], numbers_ygen[it], true);", "OP", operation);
time_gen = current_time_monotonic() - time_gen;
time_asm := current_time_monotonic();
- for 0..SIZE_DATA-1 #insert #run replace("numbers_zasm[it] = OP(numbers_x[it], numbers_y[it]);", "OP", operation);
+ for 0..DATA_SIZE-1 #insert #run replace("numbers_zasm[it] = OP(numbers_xasm[it], numbers_yasm[it]);", "OP", operation);
time_asm = current_time_monotonic() - time_asm;
- for 0..SIZE_DATA-1 assert(numbers_zgen[it] == numbers_zasm[it]);
+ for 0..DATA_SIZE-1 assert(numbers_zgen[it] == numbers_zasm[it]);
- perf_gen := cast(float)SIZE_DATA/cast(float)to_microseconds(time_gen);
- perf_asm := cast(float)SIZE_DATA/cast(float)to_microseconds(time_asm);
+ perf_gen := cast(float)DATA_SIZE/cast(float)to_microseconds(time_gen);
+ perf_asm := cast(float)DATA_SIZE/cast(float)to_microseconds(time_asm);
best_gen = max(best_gen, perf_gen);
best_asm = max(best_asm, perf_asm);
}
if print_result {
if type == s8 || type == u8 write_string(" ");
- print("% | % | % |\n", type, best_gen, best_asm);
+ print("% | % | % | %\n", type, best_gen, best_asm, DATA_SIZE);
}
return best_gen, best_asm;
}