python-awips/pypies/testSerializingPython.py
Shay Carter 5f070d0655 Commit of all v20 ufpy code:
- code brought over from the following raytheon repos and directories:
  - awips2 repo:
    - awips2/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.alertviz/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.mpe/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.dataplugin.text/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.dataplugin.grid/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.activetable/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.management/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.dataplugin.radar/pythonPackages
    - awips2/edexOsgi/com.raytheon.uf.common.site/pythonPackages
  - awips2-core repo:
    - awips2-core/common/com.raytheon.uf.common.auth/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.message/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.localization/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.datastorage/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.pointdata/pythonPackages
    - awips2-core/common/com.raythoen.uf.common.pypies/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.dataaccess/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.dataplugin.level/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.serialization/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.time/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.dataplugin/pythonPackages
    - awips2-core/common/com.raytheon.uf.common.dataquery/pythonPackages
  - awips2-rpm repo: had to untar and unzip the thirft repo, then go into /lib/py and run `python setup.py build` and then copy in from the build/ subdirectory
    -foss/thrift-0.14.1/packaged/thrift-0.14.1/lib/py/build/lib.macosx-10.9-x86_64-cpython-38/thrift
2023-09-12 13:38:19 -06:00

47 lines
No EOL
1.2 KiB
Python

import pypies, numpy
from dynamicserialize.dstypes.com.raytheon.uf.common.pypies import TestStoreRequest
from timeit import Timer
ntrials = 10
def main():
timer = Timer("serialize(obj)", "from __main__ import serialize, makeObject; obj = makeObject()")
print("serializing took", sum(timer.repeat(ntrials,1))/ntrials,'seconds')
obj = makeObject()
b = serialize(obj)
writeOut(b)
def makeObject():
obj = TestStoreRequest()
obj.setGroupName("/155/uyp/gfe")
obj.setSize(8)
obj.setOtherName("2382;332")
obj.setNullTest(None)
obj.setValue(4.5)
obj.setGood(False)
obj.setFloatValue(3.3)
fa = numpy.zeros((302088,), numpy.float32)
fa[0] = 5.5
obj.setFloatArray(fa)
ia = numpy.zeros((302088,), numpy.int32)
ia[0] = 18
obj.setIntArray(ia)
obj.setTestMap({'tue':4.3, 'wed':5.6})
obj.setTestSet(set([4, 2, 8]))
obj.setSomeEnum('THIRD')
return obj
def serialize(obj):
dsm = pypies.DynamicSerializationManager.DynamicSerializationManager()
b = dsm.serializeObject(obj)
return b
def writeOut(b):
f = open('/tmp/pyOut', 'w')
f.write(b)
f.flush()
f.close()
if __name__ == '__main__':
main()