On 11/2/06, Andy Bradford <[EMAIL PROTECTED]> wrote:
By the way, here's a tally of runtimes on my PC:

Python: .045ms on average
Tcl [1]: .016ms on average
Perl: .0125ms on average

Looks like Perl wins out on speed. I didn't have PHP installed (who uses
PHP for scripting anyways) so someone else may want to provide it.

[1] Here's my unoptimized Tcl version:

Here is my Tcl version:

proc solve {} {
   fconfigure stdout -buffering full
   while {[gets stdin line] != -1} {
       set match_p 1
       foreach x [lrange $line 0 end-1] y [lrange $line 1 end] {
           if {$x == $y || abs($x - $y) >= [llength $line]} then {
               set match_p 0; break
           }
       }
       if {$match_p} then {puts "match"} else {puts "not a match"}
   }
}; solve

For really short amounts of input (such as the sample data) you'll get
slightly faster results by commenting out the first and last line
(#proc solve ... and #}; solve).

However, for the actual test, where I assume there would be a large
amount of input, the cost of byte-code compiling it by putting it in a
[proc] would be amortized/neglibile in relation to the speed increase.

Of course sadly thats all moot since Tcl isn't one of the chosen languages.

Michael

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to