[Python-talk] Profile results... Better pack?
Kent Johnson
kent37 at tds.net
Thu Oct 15 15:52:31 EDT 2009
On Thu, Oct 15, 2009 at 2:24 PM, <bruce.labitt at autoliv.com> wrote:
> kent3737 at gmail.com wrote on 10/15/2009 12:58:47 PM:
>> Can you show your code? I suggest you post this specific question to
>> comp.lang.python with a code sample of what you are doing now. Even
>> better would be a short, standalone program that demonstrates the
>> timing. That newsgroup loves optimization questions.
>>
>
> I don't see why not.
> Do you have to sign up to post?
No, it is actually a Usenet news group. You can post from any
newsreader or use Google:
http://groups.google.com/group/comp.lang.python/topics?gvc=1
> I don't know how to do the random number generation in straight python...
>
> I think this is a CME (complete minimal example).
>
> # ===============================================
> from numpy import random
> from struct import pack
> import time
>
> lenfft = 10084200
> sigma = 0.1
> stim = random.normal(0., sigma, lenfft) # 10084200 gaussian random numbers
> (doubles)
>
> fmt = '!h'+str(stim.size)+'d' # makes fmt = '!h10084200d'
> cmd = 4
>
> startTime = time.time()
> packdat = pack( fmt, cmd, *stim )
> elapsed = time.time() - startTime
> print 'Time to pack elements ', elapsed
> # ==============================================
Is your actual input in a numpy array? If so then this is fine. If
your real input is a Python list then I would just create a list of
floats. In your post, explain the context a little - that you are
doing this for transmission over a socket.
Kent
More information about the Python-talk
mailing list