Re: How to increase the speed of this program?



Fredrik Lundh wrote:

John Machin wrote:

I'm extremely agnostic about the spelling :-) IOW I'd be very glad of
any way [pure Python; e.g. maintaining my own version of the array
module doesn't qualify] to simply and rapidly create an array.array
instance with typecode t and number of elements n with each element
initialised to value v (default to be the zero appropriate to the
typecode).

array(t, [v])*n

Of course Leo was already there before I messed it up again.

$ python2.5 -m timeit -s'from array import array; s = "abc"' 'a = array("c",
s); a*1000000'
10 loops, best of 3: 53.5 msec per loop

$ python2.5 -m timeit -s'from array import array; s = "abc"' 'a = array("c",
s); s*1000000'
100 loops, best of 3: 7.63 msec per loop

So str * N is significantly faster than array * N even if the same amount of
data is copied.

Peter

.



Relevant Pages

  • Re: Global array operations: a performance hit?
    ... as if many DO loops were executed instead than just one. ... global array operations then? ... Note that the usual terminology is something more like "whole array ... once in a while they might also get you faster execution, ...
    (comp.lang.fortran)
  • Re: Puppy Mastiff wants to Nip at Faces
    ... first couple of weeks of an introductory data structures ... it seems to me by my recollection that loops were... ... in my first college textbook on structured programming. ... they did was loop through an array to show how you could easily access ...
    (rec.pets.dogs.behavior)
  • Re: Inefficient code?
    ... line is written to the output file. ... or read it into an array. ... # Backup File Field Positions ... Define 'my %found;' above the loops. ...
    (perl.beginners)
  • Re: Global array operations: a performance hit?
    ... when using array operations you have additional information ... which is not always the case in DO loops. ... optimizing array expressions. ... The compiler has to ...
    (comp.lang.fortran)
  • Re: Problem with reading data from files?
    ... Blocked reallocations? ... Not using an array at all is another. ... which is the use of infinite DO loops. ... All I saw was the "pick a large number" scheme, ...
    (comp.lang.fortran)