def single_thread_test(nObjects=3): time_point = time.time() print('clear') mq.fifo.clear() print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: ', time_consumed) time_point = time.time() for i in range(nObjects): workspec = WorkSpec() workspec.workerID = i data = {'random': [random.random(), random.random()]} workspec.workAttributes = data # print('put') mq.put(workspec) # print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: {0} sec ; Avg: {1} obj/sec '.format( time_consumed, nObjects / time_consumed)) print('size', mq.size()) print('peek') print(mq.peek()) time_point = time.time() for i in range(nObjects): # print('get') obj = mq.get(timeout=3) # print(obj) # print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: {0} sec ; Avg: {1} obj/sec '.format( time_consumed, nObjects / time_consumed))
def single_thread_test(nObjects=3, protective=False): time_point = time.time() print('clear') mq.fifo.clear() print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: ', time_consumed) time_point = time.time() for i in range(nObjects): workspec = WorkSpec() workspec.workerID = i data = {'random': [random.random(), random.random()]} workspec.workAttributes = data # print('put') mq.put(workspec) # print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: {0} sec ; Avg: {1} obj/sec '.format(time_consumed, nObjects/time_consumed)) print('size', mq.size()) print('peek') print(mq.peek()) time_point = time.time() for i in range(nObjects): # print('get') obj = mq.get(timeout=3, protective=protective) # print(obj) # print('size', mq.size()) time_consumed = time.time() - time_point print('Time consumed: {0} sec ; Avg: {1} obj/sec '.format(time_consumed, nObjects/time_consumed))
def _put_object(i_index): workspec = WorkSpec() workspec.workerID = i_index data = {'random': [(i_index**2) % 2**16, random.random()]} workspec.workAttributes = data mq.put(workspec)