############################################################################### # # microBenchmarks.eagle -- # # Extensible Adaptable Generalized Logic Engine (Eagle) # Micro-Benchmarks for Tcl/Eagle # # Copyright (c) 2007-2010 by Joe Mistachkin. All rights reserved. # # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. # # RCS: @(#) $Id: $ # ############################################################################### source [file join [file dirname [info script]] tclHelper.eagle] ############################################################################### set channel stdout if {[info exists argv] && [llength $argv] > 0} then { set channel [open [lindex $argv 0] {WRONLY CREAT TRUNC}] } proc isStdout {} { return [expr {$::channel eq "stdout"}] } ############################################################################### if {[catch {version} version] == 0} then { puts $channel [appendArgs \" $version \"] } else { set threaded [info exists tcl_platform(threaded)] set debug [info exists tcl_platform(debug)] puts $channel [appendArgs \" "Tcl v" $tcl_patchLevel \ [expr {$threaded ? " Threaded" : " Non-Threaded"}] \ [expr {$debug ? " Debug" : " Release"}] \"] } if {[isStdout]} then { puts $channel [appendArgs [string repeat * 70] \n] } else { puts $channel "\"name\"\t\"microseconds\"" flush $channel } ############################################################################### proc do_time { name script qty } { if {[isStdout]} then { puts -nonewline $::channel [appendArgs $name " * " $qty " ... "] puts $::channel [uplevel 1 [list time $script $qty]] } else { puts -nonewline $::channel [appendArgs \" $name \"\t] flush $::channel puts $::channel [appendArgs \" \ [lindex [uplevel 1 [list time $script $qty]] 0] \"] flush $::channel } } ############################################################################### if {[isEagle]} then { do_time nopCmd { nop } 10000 } else { puts $channel "\"nopCmd\"\t\"1\"" } ############################################################################### proc proc_nop {} {} do_time nopProc { proc_nop } 10000 ############################################################################### do_time whileIncr { set x 0; while {$x < 1000} {incr x} } 1000 ############################################################################### do_time whileIfIncr { set x 0; while {$x < 1000} {if {!$x} then {incr x} else {incr x 2}} } 1000 ############################################################################### do_time forIncrLappend { set y [list]; for {set x 0} {$x < 1000} {incr x} {lappend y $x} } 10 ############################################################################### do_time forIncrRandLappend { set y [list] for {set x 0} {$x < 1000} {incr x} { lappend y [expr {int(rand() * 1000)}] } } 10 ############################################################################### do_time catchError { catch {error test} x } 1000 ############################################################################### do_time stringMatch { string match *MN* [string repeat ABCDEFGHIJKLMNOPQRSTUVWXYZ 1000] } 1000 ############################################################################### if {$tcl_version >= 8.5 || [isEagle]} then { do_time constExpr { expr {wide(11)*(2*3**2*5*(2**4*3**2*(2**2*7**2+1)*4001+1)+1)} } 1000 } else { puts $channel "\"constExpr\"\t\"1\"" } ############################################################################### if {[isEagle]} then { do_time simpleInvokeInstance { set o [object create System.String test1] object invoke $o Format {{0}} test2 object dispose $o } 1000 ############################################################################# do_time simpleInvokeStatic { object invoke System.String Format {{0}} test1 } 1000 } else { puts $channel "\"simpleInvokeInstance\"\t\"1\"" puts $channel "\"simpleInvokeStatic\"\t\"1\"" } ############################################################################### if {[isEagle] && \ [package vcompare $eagle_platform(patchLevel) 1.0.3599.38186] == 1} then { do_time complexInvokeInstance { set o [object create System.String test1] object invoke $o ToString.Format {{0}} test2 object dispose $o } 1000 ############################################################################# do_time complexInvokeStatic { object invoke System.String.Empty ToString.Format {{0}} test1 } 1000 } else { puts $channel "\"complexInvokeInstance\"\t\"1\"" puts $channel "\"complexInvokeStatic\"\t\"1\"" } ############################################################################### if {[isStdout]} then { puts $channel [appendArgs \n [string repeat * 70] \n] } else { flush $channel close $channel }