📄 testpythonmarshallingperf.py
字号:
resultList.append(theMap) mc.setRootObject(resultList) print ("\nVerify you can format, marshall, and unmarshall an object " + "that references a map class but does not define the map class " + "in the context:") print "\nFormatObject result without map class definition in context:" print formatObject(mc) result = mc.marshall() print "\nMarshalled string:" print result print "\nLength of marshalled string: %s" % (len(result)) mc2 = unmarshall(result) print "\nUnmarshall and call FormatObject on the context:" print formatObject(mc2) # Verify that calling formatObject on an object that references a # map class but does not provide a marshalling context does not # cause an error. outputList = mc2.getRootObject(); print "\nPrint root list object as a formatted string:\n%s" % \ (formatObject(outputList)) # Now create another map class definition with no keys and add it to # the context but don't reference it. myMapClass2 = STAFMapClassDefinition("STAF/Test/MyMapClassDefinition2"); mc.setMapClassDefinition(myMapClass2); print "\nFormatObject result with wrong map class definition in context:" print formatObject(mc) print "\nMarshalling string with wrong map class definition in context:" result = mc.marshall() print result print "\nLength of marshalled data: %s" % (len(result)) mc2 = unmarshall(result) print "\nUnmarshall and call FormatObject on the context:" print formatObject(mc) # Now add the right map class definition to the context mc.setMapClassDefinition(myMapClass) print "\nFormatObject result with map class definition in context:" print formatObject(mc) # Now create an instance for the map class with no keys print "\nAdd a map object created for the map class definition with no keys" theMap2 = myMapClass2.createInstance() theMap2["KeyXXX"] = "ValueXXX" theMap2["KeyZZZ"] = "ValueZZZ" resultList.append(theMap2) mc.setRootObject(resultList) # Verify that you can format, marshall, and unmarsharll an object that # references a map class that doesn't have any keys defined. print "\nVerify you can format, marshall, and unmarshall an object that references a map class without any keys defined:" print "\nFormatObject Result:" print formatObject(mc) result = mc.marshall() print "\nMarshalledString: \n%s" % (result) print "\nLength of marshalled data: %s" % (len(result)) print "\nUnmarshall and call FormatObject on the context" mc2 = unmarshall(result) print formatObject(mc2) # Add keys to the second map class definition. One that doesn't match # the entry and one that does myMapClass2.addKey("KeyYYY", "Key YYY"); myMapClass2.addKey("KeyXXX", "Key XXX"); # Verify that you can format, marshall, and unmarshall an object that # references a map class that has a key that it doesn't provide an # entry for. print "\nVerify you can format, marshall, and unmarshall an object that references a map class without a key that it doesn't provide an entry for:" print "\nFormatObject Result:" print formatObject(mc) result = mc.marshall() print "\nMarshalledString: \n%s" % (result) print "\nLength of marshalled data: %s" % (len(result)) print "\nUnmarshall and call FormatObject onn the context" mc2 = unmarshall(result) print formatObject(mc2) resultList = [] ####################################### # Test Python marshalling performance # ####################################### print "\n**************************************************************" print "Test Performance for Marshalling, FormatObject, and Unmarshall" print "**************************************************************" entries = int(args[1]) # Test using a list with the specified number of entries print "\nTest using a list with %s entries\n" % (entries) myList = [] for i in range(0, entries): myList.append("entryValue ##%s" % (i)) mc = STAFMarshallingContext() mc.setRootObject(myList) print "FormatObject starting..." starttime = time.time() # record starting time for formatObject formatObject(mc) #print formatObject(mc) elapsed = time.time() - starttime print "FormatObject Elapsed Time: %.0f seconds" % (elapsed) print "Marshalling starting..." starttime = time.time() # record starting time for marshalling result = mc.marshall() elapsed = time.time() - starttime print "Marshalling Elapsed Time: %.0f seconds" % (elapsed) #print result print "Length of marshalled string: %s" % (len(result)) print "Unmarshalling starting..." starttime = time.time() # record starting time for marshalling mc = unmarshall(result) elapsed = time.time() - starttime print "Unmarshalling Elapsed Time: %.0f seconds" % (elapsed) #print formatObject(mc) myList = [] # Test using a map with the specified number of entries print "\nTest using a map with %s entries\n" % (entries) myMap = {} for i in range(0, entries): myMap["key%s" % (i)] = "value%s" % (i) mc = STAFMarshallingContext() mc.setRootObject(myMap) print "FormatObject starting..." starttime = time.time() # record starting time for formatObject formatObject(mc) #print formatObject(mc) elapsed = time.time() - starttime print "FormatObject Elapsed Time: %.0f seconds" % (elapsed) print "Marshalling starting..." starttime = time.time() # record starting time for marshalling result = mc.marshall() elapsed = time.time() - starttime print "Marshalling Elapsed Time: %.0f seconds" % (elapsed) #print result print "Length of marshalled string: %s" % (len(result)) print "Unmarshalling starting..." starttime = time.time() # record starting time for marshalling unmarshall(result) elapsed = time.time() - starttime print "Unmarshalling Elapsed Time: %.0f seconds" % (elapsed) myMap = {} # Test using a list (with the specified number of entries / 10) of map # class objects each with 10 keys numEntries = int(entries / 10) if numEntries < 1 and entries > 0: numEntries = 1 numKeys = 10 print "\nTest using a list with %s entries of map class objects each with %s keys\n" % (numEntries, numKeys) # Define a map class with 10 keys myMapClass = STAFMapClassDefinition('STAF/Test/MyMapClassDefinition') for k in range(1, numKeys + 1): myMapClass.addKey("key%s" % (k), "Key #%s" % (k)) # Create a marshalling context and assign the map class definition mc = STAFMarshallingContext() mc.setMapClassDefinition(myMapClass) resultList = [] for i in range(1, numEntries + 1): # Create an instance of this map class definition and assign # data to the map class instance theMap = myMapClass.createInstance() for j in range(1, numKeys + 1): theMap["key%s" % (j)] = "Value %s %s" % (j, i) resultList.append(theMap) mc.setRootObject(resultList) print "FormatObject starting..." starttime = time.time() # record starting time for formatObject formatObject(mc) #print formatObject(mc) elapsed = time.time() - starttime print "FormatObject Elapsed Time: %.0f seconds" % (elapsed) print "Marshalling starting..." starttime = time.time() # record starting time for marshalling result = mc.marshall() elapsed = time.time() - starttime print "Marshalling Elapsed Time: %.0f seconds" % (elapsed) #print result print "Length of marshalled string: %s" % (len(result)) print "Unmarshalling starting..." starttime = time.time() # record starting time for marshalling unmarshall(result) elapsed = time.time() - starttime print "Unmarshalling Elapsed Time: %.0f seconds" % (elapsed) resultList = [] sys.exit(0)if __name__ == "__main__": sys.exit(main())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -