Python isn't necessarily slow

Ronny Wichers Schreur ronny at cs.kun.nl
Tue Mar 5 04:19:58 EST 2002


Siegfried Gonzi wrote (in comp.lang.python):

> After my nightmare using Clean [..] [Clean] is a useless big
> pile of shit! [..] Clean's array-type-system is an impudent
> scandal for its own

As one of the Clean developers, I'm sorry to read that you're
frustrated with our language.

I believe that you should use the right tools for the right
job. This depends on the job, but also on your own preference.
Judging from your comments you seem more at ease with a language
that's not statically typed and that doesn't enforce referential
transparency.

Maybe Python with NumPy is the right choice for your job and
you could even use functional programming techniques in Python.

One serious objection to your Clean program. The implementation
of CharPosInString and ConvertStringtoString_List are both
quadratic in the number of columns in each row. CharPosInString
because of the call to filter in each iteration and
ConvertStringtoString_List because of the calls to length
and (!!) (list subscription).

Both functions should run in linear time, for example

    CharPosInString:: !Char !String -> [Int]
    CharPosInString char string
        =   [i \\ c <-: string & i <- [0..] | c == char]

    ConvertStringtoString_List:: !String ![Int] -> [String]
    ConvertStringtoString_List string list
        =   [string % (start+1, stop-1)
                        \\ start <- list & stop <- tl list]

(also remove the 0 (initial accumulator) in the calls). This
modification should improve the running time with a factor
ten or so.

Happy hacking.


Ronny Wichers Schreur





More information about the Python-list mailing list