[tcltk-perl] RE: [Activetcl] why simple Tcl script have very different executi on time...
Brought to you by:
hobbs
From: Konovalov, V. <vko...@sp...> - 2004-10-19 04:34:48
|
> > Give following simple script: > > > > for {set i 0} {$i < 1000000} {incr i} {} > > > > If invoked from file: tclsh a.tcl > > finishes execution in about 6 seconds on my PC. > > > When I input same string from within "tclsh" shell it > finishes in 3 seconds. > > In general, Tcl does not compile toplevel code, since it is > expected this code runs once. Not great for large loops. If > you have a large loop, put it in a proc if you want it to run > fast: > > proc test {} { > for {set i 0} {$i < 1000000} {incr i} {} > } > test Thanks, that's really it. Initially my test was: perl -MTcl -we "$t0=Win32::GetTickCount();$i=new Tcl;$i->Eval('for {set i 0} {$i < 1000000} {incr i} {}');print Win32::GetTickCount()-$t0;" 6119 Now it is: perl -MTcl -we "$t0=Win32::GetTickCount();$i=new Tcl;$i->Eval('proc test {} {for {set i 0} {$i < 1000000} {incr i} {}};test');print Win32::GetTickCount()-$t0;" 1312 Will use this knowledge, as it makes sence to me. Best regards, Vadim. |