1# 2# timings of libm functions 3# under various extension techniques 4# 1) Tcl's builtin expr math functions 5# 2) Ffidl's ::ffidl::callout 6# 3) SWIG wrappers 7# 4) ::dll's ::dll::declare 8# 9lappend auto_path . 10package require Ffidl 0.1 11package require Ffidlrt 0.1 12 13# 14# you need to install the ::dll package, compile for your 15# system, only Windows and Linux supported, and point this 16# load at the result library. no harm if you leave it as 17# it is, the script catches any missing ::dll errors. 18# 19set nodll [catch {load ../../dll-1.0/unix/libdll10.so}] 20 21# 22# This Swig test extension is built by "make test" in 23# the directory above. 24# 25set noswig [catch {load [::ffidl::find-lib mathswig]}] 26 27# 28# time, time, who's got the time. 29# 30proc timing {} { 31 global nodll noswig 32 set lib [::ffidl::find-lib m] 33 set a [expr {1.23456789+0.0}] 34 set b [expr {9.87654321+0.0}] 35 proc nil {a} { set a } 36 time {nil $a} 10000 37 set t [time {nil $a} 10000]; puts "time for nil: $t" 38 39 ::ffidl::callout fficos {double} double [::ffidl::symbol $lib cos] 40 if { ! $nodll } {::dll::declare $lib cos dllcos d d} 41 if { ! $nodll } {set t [time {dllcos $a} 10000]; puts "time for dll cos: $t"} 42 if { ! $noswig} {set t [time {cos $a} 10000]; puts "time for swig cos: $t"} 43 set t [time {fficos $a} 10000]; puts "time for ffidl cos: $t" 44 set t [time {expr {cos($a)}} 10000]; puts "time for expr cos: $t" 45 46 ::ffidl::callout ffisqrt {double} double [::ffidl::symbol $lib sqrt] 47 if { ! $nodll} {::dll::declare $lib sqrt dllsqrt d d} 48 if { ! $nodll} {set t [time {dllsqrt $a} 10000]; puts "time for dll sqrt: $t"} 49 if { ! $noswig} {set t [time {sqrt $a} 10000]; puts "time for swig sqrt: $t"} 50 set t [time {ffisqrt $a} 10000]; puts "time for ffidl sqrt: $t" 51 set t [time {expr {sqrt($a)}} 10000]; puts "time for expr sqrt: $t" 52 53 ::ffidl::callout ffiatan2 {double double} double [::ffidl::symbol $lib atan2] 54 if { ! $nodll} {::dll::declare $lib atan2 dllatan2 d d d} 55 if { ! $nodll} {set t [time {dllatan2 $a $b} 10000]; puts "time for dll atan2: $t"} 56 if { ! $noswig} {set t [time {atan2 $a $b} 10000]; puts "time for swig atan2: $t"} 57 set t [time {ffiatan2 $a $b} 10000]; puts "time for ffidl atan2: $t" 58 set t [time {expr {atan2($a,$b)}} 10000]; puts "time for expr atan2: $t" 59 60 ::ffidl::callout ffiexp {double} double [::ffidl::symbol $lib exp] 61 if { ! $nodll} {::dll::declare $lib exp dllexp d d} 62 if { ! $nodll} {set t [time {dllexp $a} 10000]; puts "time for dll exp: $t"} 63 if { ! $noswig} {set t [time {exp $a} 10000]; puts "time for swig exp: $t"} 64 set t [time {ffiexp $a} 10000]; puts "time for ffidl exp: $t" 65 set t [time {expr {exp($a)}} 10000]; puts "time for expr exp: $t" 66 67 ::ffidl::callout ffilog {double} double [::ffidl::symbol $lib log] 68 if { ! $nodll} {::dll::declare $lib log dlllog d d} 69 if { ! $nodll} {set t [time {dlllog $a} 10000]; puts "time for dll log: $t"} 70 if { ! $noswig} {set t [time {log $a} 10000]; puts "time for swig log: $t"} 71 set t [time {ffilog $a} 10000]; puts "time for ffidl log: $t" 72 set t [time {expr {log($a)}} 10000]; puts "time for expr log: $t" 73 74 ::ffidl::callout ffifloor {double} double [::ffidl::symbol $lib floor] 75 if { ! $nodll} {::dll::declare $lib floor dllfloor d d} 76 if { ! $nodll} {set t [time {dllfloor $a} 10000]; puts "time for dll floor: $t"} 77 if { ! $noswig} {set t [time {floor $a} 10000]; puts "time for swig floor: $t"} 78 set t [time {ffifloor $a} 10000]; puts "time for ffidl floor: $t" 79 set t [time {expr {floor($a)}} 10000]; puts "time for expr floor: $t" 80} 81 82timing 83