Posted to tcl by damkerngt at Fri Oct 18 13:37:00 GMT 2013view raw
- # Benchmark tests for [file utime].
- # See the ticket: http://core.tcl.tk/tcl/info/605074ede5
- # and the patch: http://core.tcl.tk/tcl/info/9c8b16fd68
- # Damkerng T., 18-Oct-2013.
- # NOTE: You can run this on standard builds of Tcl 8.5/8.6 too.
- # ([file utime] calls will just be skipped/aborted.)
- # Benchmark results:
- #
- # The penalty of stat() calls seems to vary from machine to machine.
- # But it seems to be determined by the two major factors:
- # immediately previous and/or current disk I/O and free memory left.
- #
- # Here are the results from running this script with
- # Tcl 8.6.1 (damkerngt-file-utime branch):
- #
- # On Intel Core2 Duo 1.6 GHz memory 2Gb (Windows XP):
- # NOTE: "massive writes" and "no writes" refer to whether the directory
- # tmp-for-benchmarking exists before running, or not.
- # "Massive writes" = tmp-for-benchmarking does not exist
- #
- # Case 1: about 2/3 of memory available (1.1 Gb from 1.8 Gb)
- # Massive writes No writes
- # file mtime 29.313 seconds 27.063 seconds
- # file utime 19.297 seconds 18.843 seconds
- #
- # Case 2: about 1/3 of memory available (0.6 Gb from 1.8 Gb)
- # Massive writes No writes
- # file mtime 133.219 seconds 125.047 seconds
- # file utime 24.359 seconds 25.406 seconds
- #
- # On AMD 1.3 MHz memory 3 Gb (Ubuntu 9.10):
- # The remaining memory seems to have no impact even when over 90% used.
- # So I will report only the difference between disk I/O cases:
- #
- # Massive writes No writes
- # file mtime 47.188 seconds 2.966 seconds
- # file utime 2.680 seconds 2.797 seconds
- # Running environment.
- set machine "$tcl_platform(os) $tcl_platform(osVersion) $tcl_platform(machine)"
- puts "Tcl $tcl_patchLevel on $machine"
- # Basic [file mtime], [file utime] performance.
- proc BasicBenchmarks {} {
- set file \$\$touch-[pid].dat
- set fd [open $file w]; close $fd
- puts "mtime: [time {file mtime $file [clock seconds]} 20000]"
- catch {
- puts "utime: [time {file utime $file [clock seconds]} 20000]"
- }
- file delete $file
- puts ""
- }
- BasicBenchmarks
- # Parameter settings:
- # WARNING: This test will create a new directory "tmp-for-bechmarking",
- # and a whole lot of files and sub-directories under it.
- # Be sure you don't already have such a directory (you can change its name below),
- # and have enough disk space (default settings require at least 500 Mb).
- set dir tmp-for-benchmarking
- #~ set extras ""
- set extras a/b/c ;# extra depth makes it even more realistic (read "slower")
- set size 50000 ;# number of files to bechmark
- set step 1000
- set filesize 10240
- set format %0[string length $size]d
- foreach v {dir extras size step filesize} {
- puts "$v = [set $v]"
- }
- # Helper routine
- proc Elapse {startMilliseconds} {
- set nmsecs [expr {[clock milliseconds] - $startMilliseconds}]
- return [format %.03f [expr {$nmsecs/1000.0}]]
- }
- # Preparing files.
- # NOTE: You need to create all these files only once.
- # If you want to re-create all these files, just purge your bechmark $dir.
- if {![file exists $dir]} {
- puts "preparing files..."
- set n 1
- set start [clock milliseconds]
- file mkdir $dir
- for {set i 0} {$i < $size} {incr i} {
- set file [file join $dir {*}$extras {*}[split [format $format $i] ""]]
- file mkdir [file dirname $file]
- set fd [open $file w]
- puts $fd [string repeat * $filesize]
- close $fd
- if {[incr n] % $step == 0} {
- puts "prepare: $n files, [Elapse $start] seconds passed"
- }
- }
- puts "done in [Elapse $start] seconds"
- puts "See what happens after massive disk writes..."
- BasicBenchmarks
- }
- # Here is the test.
- # It tests both [file mtime] and [file utime] (see damkerngt-file-utime branch).
- # Standard tclsh.exe has only [file mtime], but [file utime] will safely abort.
- foreach cmd {mtime utime} {
- if {[catch {
- puts "touching files (with file $cmd)..."
- set n 0
- set start [clock milliseconds]
- set timestamp [clock seconds]
- for {set i 0} {$i < $size} {incr i} {
- set file [file join $dir {*}$extras {*}[split [format $format $i] ""]]
- file $cmd $file $timestamp
- if {[incr n] % $step == 0} {
- puts "$cmd: $n files, [Elapse $start] seconds passed"
- }
- }
- puts "done in [Elapse $start] seconds"
- }]} {
- puts "aborted"
- }
- }