From 06ab91f038972610338e77f4f488c7ef5c132e69 Mon Sep 17 00:00:00 2001 From: xchaos Date: Tue, 29 Jan 2008 17:11:54 +0000 Subject: [PATCH] performance test - write, fwrite and cll1 single arugment echo added git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@48 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 19 +-- demos/advanced-hello-world.c | 6 +- demos/performance/cll1-echo.c | 8 + demos/performance/cout.cpp | 5 +- demos/performance/fputs.c | 11 +- demos/performance/print.rb | 1 + demos/performance/print2.rb | 1 + demos/performance/printf.c | 11 +- demos/performance/printf2.c | 3 +- demos/performance/puts.c | 11 +- demos/performance/test-performance.sh | 111 +++++++++----- demos/performance/test-performance2.sh | 86 ++++++++--- demos/performance/test-results | 195 +++++++++++++++++-------- demos/performance/test-results2 | 153 +++++++++++++------ demos/performance/write.c | 10 +- demos/performance/write2.c | 1 - 16 files changed, 442 insertions(+), 190 deletions(-) create mode 100644 demos/performance/cll1-echo.c diff --git a/cll1.h b/cll1.h index 09195a5..0a4b0ea 100644 --- a/cll1.h +++ b/cll1.h @@ -115,8 +115,8 @@ '----------------------------------------------------------------------- */ #define push(NODE,HEAD) ( NODE ? ((NODE->__next=HEAD),(HEAD=NODE)) : NULL ) #define pop(NODE,HEAD) ( HEAD ? ((NODE=HEAD->__next),free(HEAD),(HEAD=NODE)) : (NODE=NULL) ) -#define append(NODE,HEAD) { void *N=NODE; /**/ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) { NODE->__next=N; break; } } -#define remove(NODE,HEAD,EXPR) { void **_D=NULL; /**/ for_search(NODE,HEAD,EXPR) { if(_D)*_D=NODE->__next; else HEAD=NODE->__next; free(NODE); } else _D=(void *)&(NODE->__next); } +#define append(NODE,HEAD) { void *N=NODE; /* <-' */ NODE->__next=NULL; for_search(NODE,HEAD,!NODE->__next) { NODE->__next=N; break; } } +#define remove(NODE,HEAD,EXPR) { void **_D=NULL; /* <-' */ for_search(NODE,HEAD,EXPR) { if(_D)*_D=NODE->__next; else HEAD=NODE->__next; free(NODE); } else _D=(void *)&(NODE->__next); } #define drop(NODE,HEAD) for( NODE=HEAD; NODE || (HEAD=NULL); HEAD=NODE, NODE=NODE->__next, free(HEAD) ) //to do: seek //to do: store @@ -126,8 +126,8 @@ #define desc_sort_by(K1,K2) (strcasecmp(K1, K2)<0) #define ascii_by(K1,K2) (strcmp(K1, K2)>0) #define desc_ascii_by(K1,K2) (strcmp(K1, K2)<0) -#define insert(NODE,HEAD,EXP,K) { if(HEAD) { void **_L=NULL, *H=HEAD; /**/ for_search(HEAD,H,EXP(HEAD->K,NODE->K)) { if(_L) {*_L=NODE; NODE->__next=HEAD; } else push(NODE,H); break; } else _L=(void *)&(HEAD->__next); if(!HEAD)*_L=NODE; HEAD=H; } else if (NODE) { push(NODE,HEAD); HEAD->__next=NULL; } } -#define sort(NODE,HEAD,EXP,K) { void *_NEXT; /**/ NODE=HEAD; HEAD=NULL; do { _NEXT=NODE->__next; NODE->__next=NULL; insert(NODE,HEAD,EXP,K); NODE=_NEXT; } while(_NEXT); } +#define insert(NODE,HEAD,EXP,K) { if(HEAD) { void **_L=NULL, *H=HEAD; /* <-' */ for_search(HEAD,H,EXP(HEAD->K,NODE->K)) { if(_L) {*_L=NODE; NODE->__next=HEAD; } else push(NODE,H); break; } else _L=(void *)&(HEAD->__next); if(!HEAD)*_L=NODE; HEAD=H; } else if (NODE) { push(NODE,HEAD); HEAD->__next=NULL; } } +#define sort(NODE,HEAD,EXP,K) { void *_NEXT; /* <-' */ NODE=HEAD; HEAD=NULL; do { _NEXT=NODE->__next; NODE->__next=NULL; insert(NODE,HEAD,EXP,K); NODE=_NEXT; } while(_NEXT); } /* .----------------------------------------------------------------------. / 7. C<<1 builtin iterators and conditionals, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ @@ -155,19 +155,20 @@ #define construct_interface(MTYPE,...) _construct_##_##MTYPE##_##_ARG1(__VA_ARGS__)((void *)__get_##_##MTYPE##_##__VA_ARGS__) #define get_object(TYPE,...) (struct TYPE *)_cll1_allocate_object(sizeof(struct TYPE), __VA_ARGS__) #define construct_object(TYPE,...) -//#define _(OBJECT,...) (_ASSERT(OBJECT),/**/(*(OBJECT->interface->_ARG1(__VA_ARGS__,)))/**/(OBJECT,OBJECT->interface->__VA_ARGS__)/**/) +//#define _(OBJECT,...) ( _ASSERT(OBJECT), (*( OBJECT->interface->_ARG1(__VA_ARGS__,) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) ) +//#define __(OBJECT,...) ( _ASSERT(OBJECT), (*( __cll1_seekmethod(OBJECT->interface,_ARG1(__VA_ARGS__,)) )) ( OBJECT,OBJECT->interface->__VA_ARGS__ ) ) /* .----------------------------------------------------------------------. / 9. implementation of C<<1 library functions, updated 2008-01-26 xCh. '----------------------------------------------------------------------- */ #define _MALLOC void *_cll1_malloc(size_t size,...) { /*temporary solution*/ return malloc(size); } -#define _CLL1_FPRINT(IOSTREAM,LASTARG) { int p2=0;char *ofs=coalesce(OFS,"\0");va_list ap; /**/ for(va_start(ap,s);s!=LASTARG;s=va_arg(ap,char *)) { if(p2 && *ofs) fputs(ofs,IOSTREAM); else p2=1; fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); if(EOL && *EOL) fputs(EOL,IOSTREAM); } +#define _CLL1_FPRINT(IOSTREAM,LASTARG) { int ofs=0; va_list ap; /* <-' */ for(va_start(ap,s);s!=LASTARG;s=va_arg(ap,char *)) { if(ofs)fputs(OFS,IOSTREAM);else ofs=1;/**/fputs(coalesce(s,NIL),IOSTREAM); } va_end(ap); fputs(EOL,IOSTREAM); } #define _PRINT void _cll1_print(char *s,...) _CLL1_FPRINT(stdout,(void *)&_cll1_print) #define _FPRINT void _cll1_fprint(FILE *f,char *s,...) _CLL1_FPRINT(f,(void *)&_cll1_fprint) -#define _CLL1_FECHO(IOSTREAM,LASTARG) { va_list ap; /**/ for(va_start(ap,s);s!=LASTARG;s=va_arg(ap,char *)) fputs(coalesce(s,NIL),IOSTREAM); va_end(ap); } +#define _CLL1_FECHO(IOSTREAM,LASTARG) { va_list ap; /* <-' */ for(va_start(ap,s);s!=LASTARG;s=va_arg(ap,char *)) fputs(coalesce(s,NIL),IOSTREAM); va_end(ap); } #define _ECHO void _cll1_echo(char *s,...) _CLL1_FECHO(stdout,(void *)&_cll1_echo) #define _FECHO void _cll1_fecho(FILE *f,char *s,...) _CLL1_FECHO(f,(void *)&_cll1_fecho) -#define _IT_INTS int _cll1_it_ints(int i, int n, ...) { int j=0;va_list ap; /**/ va_start(ap,n); while(n>=0 && j++=0 && j++ /dev/null -echo +time ./print.rb > /dev/null +echo "--------------------------------------------------- Python - range" cat print.py echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./print.py > /dev/null -echo +time ./print.py > /dev/null +echo "-------------------------------------------------- Python - xrange" cat xrange.py echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./xrange.py > /dev/null -echo +time ./xrange.py > /dev/null +echo "------------------------------------------------------------ PHP 5" cat echo.php echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./echo.php > /dev/null -echo +time ./echo.php > /dev/null +echo "-------------------------------------------------- C - gcc - write" cat write.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 write.c -o write +time gcc -O2 write.c -o write echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./write > /dev/null +time ./write > /dev/null +echo "------------------------------------------------------------- Perl" cat print.pl echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./print.pl > /dev/null -echo +time ./print.pl > /dev/null +echo "----------------------------------------------- C<<1 - gcc - print" +cat cll1-print.c +echo -n "Compiling..." +time gcc -O2 cll1-print.c -o cll1-print +echo -n "Running..." +time ./cll1-print > /dev/null + +echo "---------------------------------------------- C - g++ - std::cout" cat cout.cpp echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" g++ -O2 cout.cpp -o cout +time g++ -O2 cout.cpp -o cout echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./cout > /dev/null +time ./cout > /dev/null -echo -cat cll1-print.c +#echo "----------------------------------------------- C<<1 - tcc - print" +#cat cll1-print.c +#echo -n "Compiling..." +#time tcc -O2 cll1-print.c -o cll1-print +#echo -n "Running..." +#time ./cll1-print > /dev/null +# +#echo "------------------------------------------------- C - tcc - printf" +#cat printf.c +#echo -n "Compiling..." +#time tcc -O2 printf.c -o printf +#echo -n "Running..." +#time ./printf > /dev/null +# +#echo "--------------------------------------------------- C - tcc - puts" +#cat puts.c +#echo -n "Compiling..." +#time tcc -O2 puts.c -o puts +#echo -n "Running..." +#time ./puts > /dev/null +# +#echo "-------------------------------------------------- C - tcc - fputs" +#cat fputs.c +#echo -n "Compiling..." +#time tcc -O2 fputs.c -o fputs +#echo -n "Running..." +#time ./fputs > /dev/null +# +#echo "------------------------------------------------- C - tcc - fwrite" +#cat fwrite.c +#echo -n "Compiling..." +#time tcc -O2 fwrite.c -o fwrite +#echo -n "Running..." +#time ./fwrite > /dev/null +# + +echo "-----------------------------------------------= C<<1 - gcc - echo" +cat cll1-echo.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 cll1-print.c -o cll1-print +time gcc -O2 cll1-echo.c -o cll1-echo echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./cll1-print > /dev/null -echo +time ./cll1-echo > /dev/null +echo "------------------------------------------------- C - gcc - printf" cat printf.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 printf.c -o printf +time gcc -O2 printf.c -o printf echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./printf > /dev/null -echo +time ./printf > /dev/null +echo "--------------------------------------------------- C - gcc - puts" cat puts.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 puts.c -o puts +time gcc -O2 puts.c -o puts echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./puts > /dev/null -echo +time ./puts > /dev/null -cat fputs.c +echo "------------------------------------------------- C - gcc - fwrite" +cat fwrite.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 fputs.c -o fputs +time gcc -O2 fwrite.c -o fwrite echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./fputs > /dev/null -echo +time ./fwrite > /dev/null -cat fwrite.c +echo "-------------------------------------------------- C - gcc - fputs" +cat fputs.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 fwrite.c -o fwrite +time gcc -O2 fputs.c -o fputs echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./fwrite > /dev/null +time ./fputs > /dev/null diff --git a/demos/performance/test-performance2.sh b/demos/performance/test-performance2.sh index a4006d2..b545771 100755 --- a/demos/performance/test-performance2.sh +++ b/demos/performance/test-performance2.sh @@ -1,69 +1,111 @@ -#!/bin/sh +#!/bin/bash +echo "------------------------------------------------------------- Ruby" cat print2.rb echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./print2.rb > /dev/null +time ./print2.rb > /dev/null echo +echo "--------------------------------------------------- Python - range" cat print2.py echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./print2.py > /dev/null +time ./print2.py > /dev/null echo +echo "-------------------------------------------------- Python - xrange" cat xrange2.py echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./xrange2.py > /dev/null +time ./xrange2.py > /dev/null echo +echo "------------------------------------------------------------ PHP 5" cat echo2.php echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./echo2.php > /dev/null +time -f "%E total, %U user, %S sys" ./echo2.php > /dev/null echo +echo "-------------------------------------------------- C - gcc - write" cat write2.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 write2.c -o write2 +time gcc -O2 write2.c -o write2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./write2 > /dev/null +time ./write2 > /dev/null echo +echo "---------------------------------------------- C - g++ - std::cout" cat cout2.cpp echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" g++ -O2 cout2.cpp -o cout2 +time g++ -O2 cout2.cpp -o cout2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./cout2 > /dev/null +time ./cout2 > /dev/null echo +echo "------------------------------------------------------------- Perl" cat print2.pl echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./print2.pl > /dev/null +time -f "%E total, %U user, %S sys" ./print2.pl > /dev/null echo +#echo "------------------------------------------------- C - tcc - printf" +#cat printf2.c +#echo -n "Compiling..." +#time tcc -O2 printf2.c -o printf2 +#echo -n "Running..." +#time ./printf2 > /dev/null +#echo +# +#echo "------------------------------------------------- C - tcc - fwrite" +#cat fwrite2.c +#echo -n "Compiling..." +#time tcc -O2 fwrite2.c -o fwrite2 +#echo -n "Running..." +#time ./fwrite2 > /dev/null +#echo +# +#echo "----------------------------------------------- C<<1 - tcc - print" +#cat cll1-print2.c +#echo -n "Compiling..." +#time tcc -O2 cll1-print2.c -o cll1-print2 +#echo -n "Running..." +#time ./cll1-print2 > /dev/null +#echo +# +#echo "-------------------------------------------------- C - tcc - fputs" +#cat fputs2.c +#echo -n "Compiling..." +#time tcc -O2 fputs2.c -o fputs2 +#echo -n "Running..." +#time ./fputs2 > /dev/null +#echo +# +echo "------------------------------------------------- C - gcc - printf" cat printf2.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 printf2.c -o printf2 +time gcc -O2 printf2.c -o printf2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./printf2 > /dev/null +time ./printf2 > /dev/null echo - -cat cll1-print2.c +echo "------------------------------------------------- C - gcc - fwrite" +cat fwrite2.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 cll1-print2.c -o cll1-print2 +time gcc -O2 fwrite2.c -o fwrite2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./cll1-print2 > /dev/null +time ./fwrite2 > /dev/null echo -cat fputs2.c +echo "----------------------------------------------- C<<1 - gcc - print" +cat cll1-print2.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 fputs2.c -o fputs2 +time gcc -O2 cll1-print2.c -o cll1-print2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./fputs2 > /dev/null +time ./cll1-print2 > /dev/null echo -cat fwrite2.c +echo "-------------------------------------------------- C - gcc - fputs" +cat fputs2.c echo -n "Compiling..." -time -f "%E total, %U user, %S sys, %F page faults" gcc -O2 fwrite2.c -o fwrite2 +time gcc -O2 fputs2.c -o fputs2 echo -n "Running..." -time -f "%E total, %U user, %S sys, %F page faults" ./fwrite2 > /dev/null +time ./fputs2 > /dev/null echo diff --git a/demos/performance/test-results b/demos/performance/test-results index 9709fc5..af9d68b 100644 --- a/demos/performance/test-results +++ b/demos/performance/test-results @@ -1,22 +1,33 @@ +------------------------------------------------------------- Ruby #!/usr/bin/ruby 10000000.times { print "stuff","\n" } -Running...0:15.62 total, 14.06 user, 1.55 sys, 0 page faults +Running... +real 0m16.104s +user 0m14.353s +sys 0m1.412s +--------------------------------------------------- Python - range #!/usr/bin/python for i in range(1,10000000): print "stuff" -Running...0:08.64 total, 8.43 user, 0.21 sys, 0 page faults - +Running... +real 0m8.661s +user 0m8.465s +sys 0m0.168s +-------------------------------------------------- Python - xrange #!/usr/bin/python for i in xrange(1,10000000): print "stuff" -Running...0:08.19 total, 8.17 user, 0.00 sys, 0 page faults - +Running... +real 0m8.480s +user 0m8.433s +sys 0m0.016s +------------------------------------------------------------ PHP 5 #!/usr/bin/php5 -q -Running...0:07.08 total, 5.00 user, 2.07 sys, 0 page faults - +Running... +real 0m7.098s +user 0m5.048s +sys 0m2.024s +-------------------------------------------------- C - gcc - write #include #define RUNS 10000000UL @@ -35,14 +49,21 @@ int main (void) char *s1="stuff\n"; int l1=strlen(s1); -for (i=0;i #define RUNS 10000000UL int main() { unsigned long i; - for (i=0;i - -#define RUNS 10000000UL -int main (void) -{ -unsigned long i; -for (i=0;i #define RUNS 10000000UL int main (void) { -unsigned long i; -for (i=0;i #define RUNS 10000000UL int main (void) { -unsigned long i; -for (i=0;i #include @@ -135,5 +189,32 @@ int main (void) } return 0; } -Compiling...0:00.06 total, 0.05 user, 0.01 sys, 0 page faults -Running...0:00.53 total, 0.53 user, 0.00 sys, 0 page faults +Compiling... +real 0m0.137s +user 0m0.060s +sys 0m0.008s +Running... +real 0m0.555s +user 0m0.548s +sys 0m0.004s +-------------------------------------------------- C - gcc - fputs +#include + +#define RUNS 10000000UL +int main (void) +{ + unsigned long i; + for (i=0;i -Running...0:11.89 total, 9.90 user, 1.98 sys, 0 page faults +Running..../test-performance2.sh: line 24: -f: command not found -#include +real 0m0.001s +user 0m0.000s +sys 0m0.000s + +-------------------------------------------------- C - gcc - write #include #define RUNS 10000000UL @@ -47,9 +65,16 @@ int main (void) } return 0; } -Compiling...0:00.06 total, 0.04 user, 0.02 sys, 0 page faults -Running...0:11.79 total, 2.92 user, 8.85 sys, 0 page faults - +Compiling... +real 0m0.063s +user 0m0.044s +sys 0m0.016s +Running... +real 0m11.514s +user 0m3.572s +sys 0m7.928s + +---------------------------------------------- C - g++ - std::cout #include #define RUNS 10000000UL @@ -61,9 +86,16 @@ int main() } return 0; } -Compiling...0:00.37 total, 0.35 user, 0.02 sys, 0 page faults -Running...0:08.00 total, 5.91 user, 2.08 sys, 0 page faults - +Compiling... +real 0m0.367s +user 0m0.336s +sys 0m0.024s +Running... +real 0m8.012s +user 0m6.092s +sys 0m1.812s + +------------------------------------------------------------- Perl #!/usr/bin/perl my $i=0; @@ -71,22 +103,66 @@ for ($i=0;$i<10000000;$i++) { print ("stuff1"," ","stuff2","\n"); } -Running...0:05.69 total, 5.68 user, 0.00 sys, 0 page faults +Running..../test-performance2.sh: line 46: -f: command not found + +real 0m0.001s +user 0m0.000s +sys 0m0.004s +------------------------------------------------- C - gcc - printf #include #define RUNS 10000000UL int main (void) { unsigned long i; - for (i=0;i +#include +#define RUNS 10000000UL +int main (void) +{ + unsigned long i; + char *s1="stuff1"; + char *s2="stuff2"; + int l1=strlen(s1); + int l2=strlen(s2); + + for (i=0;i #define RUNS 10000000UL @@ -111,30 +194,12 @@ int main (void) } return 0; } -Compiling...0:00.06 total, 0.04 user, 0.02 sys, 0 page faults -Running...0:01.51 total, 1.50 user, 0.00 sys, 0 page faults - -#include -#include - -#define RUNS 10000000UL -int main (void) -{ - unsigned long i; - char *s1="stuff1"; - char *s2="stuff2"; - int l1=strlen(s1); - int l2=strlen(s2); - - for (i=0;i #include #define RUNS 10000000UL -- 2.30.2