Ejemplo n.º 1
0
def _test_serialize(test_objects, num_loops=10):
    start_time = time.time()

    for step in range(num_loops):

        ## make in-memory filehandle buffer
        fh = AugmentedStringIO( StringIO() )

        ## wrap the IN-MEMORY buffer thrift transport -- must pick
        ## the right one of these for what we are doing, requires
        ## asking more on Thrift email list
        o_transport = TTransport.TBufferedTransport(fh)

        ## use the Thrift Binary Protocol
        o_protocol = protocol(o_transport)
            
        for obj in test_objects:
            obj.write(o_protocol)

        o_transport.flush()
        
        ## maybe assert something about the size of the output buffer

    assert len(fh._fh.getvalue()) > 0

    elapsed = time.time() - start_time

    count = num_loops * len(test_objects) 

    rate = count / elapsed
    
    print '%d in %.3f seconds --> %.1f serializations per second' % (count, elapsed, rate)

    ## return the in-memory file-like object so we can use it as input to the next test
    return fh
Ejemplo n.º 2
0
def deserialize(filehandle, num_objects=1000):
    '''reads num_objects StreamItem objects out of filehandle and returns them in an array
    '''
    ## gather test data in-memory
    test_objects = []

    ## wrap the file handle in buffered transport
    i_transport = TTransport.TBufferedTransport(filehandle)
    ## use the Thrift Binary Protocol
    i_protocol = protocol(i_transport)

    ## read message instances until input buffer is exhausted
    while len(test_objects) < num_objects:
        ## instantiate a message  instance 
        msg = StreamItem()

        try:
            ## read it from the thrift protocol instance
            msg.read(i_protocol)

            ## gather the fully instantiated object into our test data
            test_objects.append(msg)

        except EOFError:
            break        

    return test_objects
Ejemplo n.º 3
0
def deserialize(filehandle, num_objects=1000):
    '''reads num_objects StreamItem objects out of filehandle and returns them in an array
    '''
    ## gather test data in-memory
    test_objects = []

    ## wrap the file handle in buffered transport
    i_transport = TTransport.TBufferedTransport(filehandle)
    ## use the Thrift Binary Protocol
    i_protocol = protocol(i_transport)

    ## read message instances until input buffer is exhausted
    while len(test_objects) < num_objects:
        ## instantiate a message  instance
        msg = StreamItem()

        try:
            ## read it from the thrift protocol instance
            msg.read(i_protocol)

            ## gather the fully instantiated object into our test data
            test_objects.append(msg)

        except EOFError:
            break

    return test_objects
Ejemplo n.º 4
0
def _test_serialize(test_objects, num_loops=10):
    start_time = time.time()

    for step in range(num_loops):

        ## make in-memory filehandle buffer
        fh = AugmentedStringIO(StringIO())

        ## wrap the IN-MEMORY buffer thrift transport -- must pick
        ## the right one of these for what we are doing, requires
        ## asking more on Thrift email list
        o_transport = TTransport.TBufferedTransport(fh)

        ## use the Thrift Binary Protocol
        o_protocol = protocol(o_transport)

        for obj in test_objects:
            obj.write(o_protocol)

        o_transport.flush()

        ## maybe assert something about the size of the output buffer

    assert len(fh._fh.getvalue()) > 0

    elapsed = time.time() - start_time

    count = num_loops * len(test_objects)

    rate = count / elapsed

    print '%d in %.3f seconds --> %.1f serializations per second' % (
        count, elapsed, rate)

    ## return the in-memory file-like object so we can use it as input to the next test
    return fh