High performance binary data

Discussion in 'Python' started by Steve, Aug 10, 2007.

  1. Steve

    Steve Guest

    I want to ready binary data from a udp socket effeciently as possible
    in python. I know of the struct package but do people have any tips
    when dealing with binary data in python? Is there a library or api
    that is faster when dealing with binary data. I am looking for a any
    one with experience or ideas on the subject. Pointers any one?

    Thanks
    Steve
     
    Steve, Aug 10, 2007
    #1
    1. Advertising

  2. On Fri, 10 Aug 2007 00:26:54 +0000, Steve wrote:

    > I want to ready binary data from a udp socket effeciently as possible
    > in python. I know of the struct package but do people have any tips
    > when dealing with binary data in python? Is there a library or api
    > that is faster when dealing with binary data. I am looking for a any
    > one with experience or ideas on the subject. Pointers any one?


    I don't know if it is faster, but maybe constructing objects with
    the `ctypes` module let you write more readable code as you can treat and
    access C ``struct``\s like objects.

    For the "fast" part of the question you might consider actually measuring
    your program, as the task may be I/O bound i.e. Python may be faster than
    the data comes in regardless of which module, `struct` or `ctypes`, you
    use to tear apart and access the data.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Aug 10, 2007
    #2
    1. Advertising

  3. Steve <> wrote:
    > I want to ready binary data from a udp socket effeciently as possible
    > in python. I know of the struct package but do people have any tips
    > when dealing with binary data in python? Is there a library or api
    > that is faster when dealing with binary data. I am looking for a any
    > one with experience or ideas on the subject. Pointers any one?


    Check out construct: http://construct.wikispaces.com/

    --
    Nick Craig-Wood <> -- http://www.craig-wood.com/nick
     
    Nick Craig-Wood, Aug 10, 2007
    #3
  4. Steve

    sturlamolden Guest

    On Aug 10, 2:26 am, Steve <> wrote:
    > I want to ready binary data from a udp socket effeciently as possible
    > in python. I know of the struct package but do people have any tips
    > when dealing with binary data in python? Is there a library or api
    > that is faster when dealing with binary data. I am looking for a any
    > one with experience or ideas on the subject. Pointers any one?


    I would recommend NumPy for manipulating binary data. It is primarily
    intended for numerics, but it is excellent for dealing with any kind
    of binary data as well. It can handle mutable buffers of any kind of
    integer or float, as well as arrays of C-like structs (record arrays
    in numpy). You can typecast and create subarrays without copying any
    data, simply by providing a new "view" into the buffer. You can also
    get access to strided subsections without creating copies. And it is
    very fast.

    www.scipy.org
     
    sturlamolden, Aug 10, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rui Pacheco

    High performance file creation

    Rui Pacheco, Nov 11, 2003, in forum: Java
    Replies:
    2
    Views:
    359
    Michael Borgwardt
    Nov 11, 2003
  2. christopher diggins
    Replies:
    31
    Views:
    1,010
    Mark A. Gibbs
    Apr 9, 2004
  3. Eternal Vigilance

    Re: High Performance Counter.

    Eternal Vigilance, Jul 9, 2003, in forum: C Programming
    Replies:
    1
    Views:
    390
    Skybuck Flying
    Jul 9, 2003
  4. Theodore H. Smith
    Replies:
    4
    Views:
    358
    Theodore H. Smith
    Apr 21, 2004
  5. David McNab
    Replies:
    0
    Views:
    655
    David McNab
    Apr 23, 2004
Loading...

Share This Page