[CentralOH] 2017-11-23 道場 Scribbles 落書/惡文? 5 approaches to learning Python; WBBY; expr v incr in tcl
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Fri Nov 24 12:48:50 EST 2017
tcl fibonacci code revisited:
incr is faster than expr
For the most straightforward version, replacing the expr statement
with an incr statement reduced the execution time.
jep at casual:~/20171123$ diff fib-with-braces.tcl fib-set-incr.tcl
7c7,8
< set c [expr {$a + $b}]
---
> set c $a
> incr c $b
jep at casual:~/20171123$ for program in fib-with-braces.tcl fib-with-braces-set-incr.tcl; do echo "$program ======================================================";echo 55555 | ./"$program";done
fib-with-braces.tcl ======================================================
Please enter seed value:
Seed 55555; Result 90963...71278
Duration 759501 microseconds
fib-with-braces-set-incr.tcl ======================================================
Please enter seed value:
Seed 55555; Result 90963...71278
Duration 594213 microseconds
jep at casual:~/20171123$
For the version that used only two variables,
using incr instead of set...expr reduced the execution time,
but was still much slower than the straightforward versions.
jep at casual:~/20171123$ diff fib-with-braces-without-c.tcl fib-with-braces-incr-without-c.tcl
7c7
< set b [expr {$a + $b}]
---
> incr b $a
jep at casual:~/20171123$ for program in fib-without-c.tcl fib-with-braces-incr-without-c.tcl; do echo "$program ======================================================";echo 55555 | ./"$program";done
fib-without-c.tcl ======================================================
Please enter seed value:
Seed 55555; Result 90963...71278
Duration 1523480 microseconds
fib-with-braces-incr-without-c.tcl ======================================================
Please enter seed value:
Seed 55555; Result 90963...71278
Duration 1116895 microseconds
jep at casual:~/20171123$
source code is at the bottom.
===============================================================================
link farm
Wild Bill Bates
http://johnstonteam.blogspot.com/2010/12/wild-bills-seige.html
http://johnstonteam.blogspot.com/2008/01/i-can-kick-higher-than-you-can.html
Finding Files with mlocate: Part 3
https://www.linux.com/blog/learn/2017/11/finding-files-mlocate-part-3
How To Keep A Process/Command Running After Disconnecting SSH Session
https://www.2daygeek.com/how-to-keep-a-process-command-running-after-disconnecting-ssh-session/
LVFS makes Linux firmware updates easier
https://opensource.com/article/17/11/firmware-updates-and-lvfs
Refactoring
https://www.refactoring.com/
part of martinfowler.com
10 Best LaTeX Editors For Linux
https://itsfoss.com/latex-editors-linux/
5 approaches to learning Python
https://opensource.com/article/17/11/5-approaches-learning-python
wp:Four Freedoms
wp:The Free Software Definition
wp: prefix means Wikipedia
To get good answers, consider following the advice in the links below.
http://catb.org/~esr/faqs/smart-questions.html
http://web.archive.org/web/20090627155454/www.greenend.org.uk/rjk/2000/06/14/quoting.html
===============================================================================
source code
==> fib-with-braces-incr-without-c.tcl <==
#!/usr/bin/env tclsh
proc fib {n} {
set a 0
set b 1
for {set i 0} {$i < $n} {incr i} {
incr b $a
set a [expr {$b - $a}]
}
return $a
}
puts "Please enter seed value:"
gets stdin x
set StartTime [clock microseconds]
set Answer [fib $x]
set EndTime [clock microseconds]
puts "Seed $x; Result $Answer"
puts "Duration [expr $EndTime - $StartTime] microseconds"
==> fib-set-incr.tcl <==
#!/usr/bin/env tclsh
proc fib {n} {
set a 0
set b 1
for {set i 0} {$i < $n} {incr i} {
set c $a
incr c $b
set a $b
set b $c
}
return $a
}
puts "Please enter seed value:"
gets stdin x
set StartTime [clock microseconds]
set Answer [fib $x]
set EndTime [clock microseconds]
puts "Seed $x; Result $Answer"
puts "Duration [expr $EndTime - $StartTime] microseconds"
==> fib-with-braces.tcl <==
#!/usr/bin/env tclsh
proc fib {n} {
set a 0
set b 1
for {set i 0} {$i < $n} {incr i} {
set c [expr {$a + $b}]
set a $b
set b $c
}
return $a
}
puts "Please enter seed value:"
gets stdin x
set StartTime [clock microseconds]
set Answer [fib $x]
set EndTime [clock microseconds]
puts "Seed $x; Result $Answer"
puts "Duration [expr $EndTime - $StartTime] microseconds"
==> fib-with-braces-without-c.tcl <==
#!/usr/bin/env tclsh
proc fib {n} {
set a 0
set b 1
for {set i 0} {$i < $n} {incr i} {
set b [expr {$a + $b}]
set a [expr {$b - $a}]
}
return $a
}
puts "Please enter seed value:"
gets stdin x
set StartTime [clock microseconds]
set Answer [fib $x]
set EndTime [clock microseconds]
puts "Seed $x; Result $Answer"
puts "Duration [expr $EndTime - $StartTime] microseconds"
More information about the CentralOH
mailing list