optime() macro and gcc -O1

This commit is contained in:
Timerix22 2022-02-15 23:30:13 +03:00
parent ed10ac273e
commit a322ee4545
4 changed files with 25 additions and 18 deletions

View File

@ -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

View File

@ -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();
optime({test_all();});
optime({
Autoarr2(uint64) _ar2=Autoarr2_create(uint64,10000,20000);
Autoarr2(uint64)* ar2=&_ar2;
for(uint32 i=0;i<Autoarr2_max_length(ar2);i++)
Autoarr2_add(ar2,8);
long stop=clock();
printf("\e[96m%li\n",stop-start);
start=clock();
});
optime({
Autoarr _ar=Autoarr_create(10000,20000,UInt64);
Autoarr* ar=&_ar;
for(uint32 i=0;i<ar->max_length;i++)
Autoarr_add_uint64(ar,8);
stop=clock();
printf("\e[96m%li\n",stop-start);
});
return 0;
}

View File

@ -29,7 +29,8 @@ void printuni(Unitype v){
}
void test_all(void){
test_autoarr();
test_searchtree();
test_autoarr();
test_autoarr2();
printf("\e[96m---------------------------------------\n");
}

View File

@ -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));\
})