Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created October 26, 2021 09:28
Show Gist options
  • Save lovasoa/1bf81a2006355bdf73dce90aa4c434b8 to your computer and use it in GitHub Desktop.
Save lovasoa/1bf81a2006355bdf73dce90aa4c434b8 to your computer and use it in GitHub Desktop.
from asyncua import ua
from asyncua.ua import ua_binary
import sys
import timeit
obj = ua.WriteParameters(NodesToWrite=[
ua.WriteValue(
NodeId_=ua.NodeId("hello_world"),
Value=ua.DataValue(
Value=
ua.Variant(12.34, VariantType=ua.VariantType.Double) if i%2==0\
else ua.Variant("xyz", ua.VariantType.String),
SourceTimestamp=ua.DateTime(2021, 10, 2))
)
for i in range(50)
])
N=int(sys.argv[1]) if len(sys.argv)>1 else 1000
res = timeit.timeit(lambda: ua_binary.to_binary(ua.WriteParameters, obj), number=N)
print(f"{res/N*1000:.2f} ms per serialization")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment