Posted to tcl by daapp at Wed Sep 01 01:44:55 GMT 2010view raw
- namespace import tcl::mathop::*
-
-
- set repeat 500
-
- set from 1
- set to 10000
-
- proc nop {v} {}
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- + [* $i $i] [* 2 $i]
- }
- } $repeat]
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- expr {$i*$i+2*$i}
- }
- } $repeat]
-
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- set a [+ [* $i $i] [* 2 $i]]
- }
- } $repeat]
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- set a [expr {$i*$i+2*$i}]
- }
- } $repeat]
-
-
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- nop [+ [* $i $i] [* 2 $i]]
- }
- } $repeat]
-
- puts [time {
- for {set i $from} {$i <= $to} {incr i} {
- nop [expr {$i*$i+2*$i}]
- }
- } $repeat]
-
- ### result
- # 8720.0 microseconds per iteration
- # 8874.0 microseconds per iteration
- # 10000.0 microseconds per iteration
- # 10188.0 microseconds per iteration
- # 13062.0 microseconds per iteration
- # 12876.0 microseconds per iteration
-