Last active
September 4, 2019 19:53
-
-
Save spmallette/fea946012edcdb46396e01b06e1753f8 to your computer and use it in GitHub Desktop.
python graphbinary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cp ../../src/main/jython/gremlin_python/structure/io/graphbinaryV1.py gremlin_python/structure/io/graphbinaryV1.py | |
| cp ../../src/main/jython/gremlin_python/driver/serializer.py gremlin_python/driver/serializer.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import uuid | |
| from gremlin_python.driver import request | |
| from gremlin_python.structure.graph import Graph | |
| from gremlin_python.process.anonymous_traversal import traversal | |
| from gremlin_python.driver.serializer import ( | |
| GraphSONMessageSerializer, GraphSONSerializersV2d0, GraphSONSerializersV3d0, | |
| GraphBinarySerializersV1) | |
| from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection | |
| from gremlin_python.driver.tornado.transport import TornadoTransport | |
| graphson = GraphSONSerializersV3d0() | |
| graphbin = GraphBinarySerializersV1() | |
| graphson_message = b'{"requestId":"4888c3bb-010f-4bd4-91ed-350816d547af","status":{"message":"","code":200,"attributes":{"@type":"g:Map","@value":["host","/172.17.0.1:58159"]}},"result":{"data":{"@type":"g:List","@value":[{"@type":"g:Traverser","@value":{"bulk":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int64","@value":4}}}]},"meta":{"@type":"g:Map","@value":[]}}}' | |
| graphbin_message = b'\x81\x00Z\xdc?/\x83\x95F\xd0\x9d\x07\x8a\xf3\x90\xb7qi\x00\x00\x00\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x04host\x03\x00\x00\x00\x00\x11/172.17.0.1:58167\x00\x00\x00\x00\t\x00\x00\x00\x00\x01!\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x01' | |
| def bench_graphson(): | |
| graphson.deserialize_message(graphson_message) | |
| def bench_graphbin(): | |
| graphbin.deserialize_message(graphbin_message) | |
| if __name__ == '__main__': | |
| setup = "from __main__ import bench_graphson, bench_graphbin" | |
| import timeit | |
| print(timeit.timeit("bench_graphson()", setup=setup, number=100000)) | |
| print(timeit.timeit("bench_graphbin()", setup=setup, number=100000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import uuid | |
| from gremlin_python.driver import request | |
| from gremlin_python.structure.graph import Graph | |
| from gremlin_python.process.anonymous_traversal import traversal | |
| from gremlin_python.driver.serializer import ( | |
| GraphSONMessageSerializer, GraphSONSerializersV2d0, GraphSONSerializersV3d0, | |
| GraphBinarySerializersV1) | |
| from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection | |
| from gremlin_python.driver.tornado.transport import TornadoTransport | |
| graphson = GraphSONSerializersV3d0() | |
| graphbin = GraphBinarySerializersV1() | |
| def bench_graphson(): | |
| g = traversal().withGraph(Graph()) | |
| message = request.RequestMessage( | |
| processor='traversal', op='bytecode', | |
| args={'gremlin': g.V(1).out('knows').both('created'), | |
| 'aliases': {'g': 'g' }}) | |
| graphson.serialize_message("41d2e28a-20a4-4ab0-b379-d810dede3786", message) | |
| def bench_graphbin(): | |
| g = traversal().withGraph(Graph()) | |
| message = request.RequestMessage( | |
| processor='traversal', op='bytecode', | |
| args={'gremlin': g.V(1).out('knows').both('created'), | |
| 'aliases': {'g': 'g' }}) | |
| graphbin.serialize_message("41d2e28a-20a4-4ab0-b379-d810dede3786", message) | |
| if __name__ == '__main__': | |
| setup = "from __main__ import bench_graphson, bench_graphbin" | |
| import timeit | |
| print(timeit.timeit("bench_graphson()", setup=setup, number=100000)) | |
| print(timeit.timeit("bench_graphbin()", setup=setup, number=100000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # serialization | |
| $ env/bin/python micro.py | |
| 7.001243760001671 | |
| 7.541529953999998 | |
| # deserialization |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # serialization | |
| $ env/bin/python micro.py | |
| 7.875947140997596 | |
| 11.454598106000049 | |
| # deserialization | |
| 4.4506702899998345 | |
| 5.863707057000283 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment