From a322ee45451a35a6b9e424e5adf6efceb8a53fc4 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 15 Feb 2022 23:30:13 +0300 Subject: [PATCH] optime() macro and gcc -O1 --- DtsodC/Makefile | 2 +- DtsodC/src/main.c | 29 +++++++++++++---------------- DtsodC/src/tests/tests.c | 3 ++- DtsodC/src/tests/tests.h | 9 +++++++++ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/DtsodC/Makefile b/DtsodC/Makefile index 76d2281..fdd3696 100644 --- a/DtsodC/Makefile +++ b/DtsodC/Makefile @@ -17,7 +17,7 @@ clang: all CMPARGS= -Wall $(SRC) -o $(OUTFILE) build: @echo "\e[36m-------------[build]---------------\e[0m" - $(CMP) -O2 $(CMPARGS) + $(CMP) -O1 -flto $(CMPARGS) build_dbg: @echo "\e[36m-------------[build_dbg]---------------\e[0m" $(CMP) -O0 $(CMPARGS).dbg diff --git a/DtsodC/src/main.c b/DtsodC/src/main.c index b7d0bd4..27ce6b0 100644 --- a/DtsodC/src/main.c +++ b/DtsodC/src/main.c @@ -6,21 +6,18 @@ int main(){ setlocale(LC_ALL, "en-US.Unicode"); printf("\e[92mdtsod parser in c language!\e[97m\n"); - //test_all(); - //test_autoarr2(); - long start=clock(); - Autoarr2(uint64) _ar2=Autoarr2_create(uint64,10000,20000); - Autoarr2(uint64)* ar2=&_ar2; - for(uint32 i=0;imax_length;i++) - Autoarr_add_uint64(ar,8); - stop=clock(); - printf("\e[96m%li\n",stop-start); + optime({test_all();}); + optime({ + Autoarr2(uint64) _ar2=Autoarr2_create(uint64,10000,20000); + Autoarr2(uint64)* ar2=&_ar2; + for(uint32 i=0;imax_length;i++) + Autoarr_add_uint64(ar,8); + }); return 0; } diff --git a/DtsodC/src/tests/tests.c b/DtsodC/src/tests/tests.c index c9301d3..979afe2 100644 --- a/DtsodC/src/tests/tests.c +++ b/DtsodC/src/tests/tests.c @@ -29,7 +29,8 @@ void printuni(Unitype v){ } void test_all(void){ - test_autoarr(); test_searchtree(); + test_autoarr(); + test_autoarr2(); printf("\e[96m---------------------------------------\n"); } \ No newline at end of file diff --git a/DtsodC/src/tests/tests.h b/DtsodC/src/tests/tests.h index 24665af..9ffde7e 100644 --- a/DtsodC/src/tests/tests.h +++ b/DtsodC/src/tests/tests.h @@ -8,3 +8,12 @@ void test_autoarr(void); void test_searchtree(void); void test_all(void); void test_autoarr2(void); + +// executes codeblock and prints execution time +// should be used like optime({foo();}), because just optime(foo()) works slower +#define optime(codeblock) ({\ + clock_t start=clock();\ + (codeblock);\ + clock_t stop=clock();\ + printf("\e[96m%li\n",(stop-start));\ +})