In order to test some software I've written, I need to write values to a test harness with OLE for Process Control (OPC). The problem is, for a larger range of values I'm generating points for (say 10000), this code can take 15 seconds to execute. I need it to work in under 1 second.
import OpenOPC import argparse import sys import time from random import randint def get_args(): parser = argparse.ArgumentParser(description='Record data value changes') parser.add_argument('range', type=int, help='range of values to record') parser.add_argument('time', type=int, help='time to update values in seconds') return parser.parse_args() def get_range_list(amount, val, end): return [ ('flcon1:DataValue~Osiris_Test_Data_' + str(i + 1) + end, randint(0, val)) for i in range(amount) ] def get_time_list(amount, end): return [ ('flcon1:DataValue~Osiris_Test_Data_' + str(i + 1) + end, time.strftime('%m/%d/%Y %H:%M:%S')) for i in range(amount) ] def main(): args = get_args() opc = OpenOPC.open_client('localhost') opc.connect('SISCO.AXS4ICCP.3') print('Logging test harness value changes') while True: try: t0 = time.clock() value_list = get_range_list(args.range, 9, '.Value') time_list = get_time_list(args.range, '.TimeStamp') opc.write(value_list) opc.write(time_list) print('Wrote values') with open(str(args.range) + '.' + str(args.time) + '_1-iccp_harness.log', 'a') as f: for i in xrange(0, args.range): f.write('Osiris_Test_Data_' + str(i + 1) + ', realQTimetagExtended' + ', %g, %s, %s\n' % (value_list[i][1], 00, time_list[i][1])) t1 = time.clock() print t1-t0 print('Logged values') time.sleep(args.time) except KeyboardInterrupt: opc.close() print('Closing down logger') sys.exit() if __name__ == '__main__': main()
sleep()I don't think doing 20m instr/sec vs 2m instr/sec matters in this case. I suspect there are external causes for the speed that OP is experiencing. \$\endgroup\$