Passed
Push — master ( 44c496...c6d1eb )
by Olivier
02:29
created

perf-client.main()   A

Complexity

Conditions 3

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
nop 0
dl 0
loc 21
rs 9.5
c 0
b 0
f 0
1
import time
2
import uvloop
3
import asyncio
4
import sys
5
import logging
6
import cProfile
7
8
sys.path.insert(0, "..")
9
from asyncua import Client, ua
10
11
logging.basicConfig(level=logging.INFO)
12
_logger = logging.getLogger('asyncua')
13
14
15
async def main():
16
    url = 'opc.tcp://localhost:4840/freeopcua/server/'
17
    async with Client(url=url) as client:
18
        uri = 'http://examples.freeopcua.github.io'
19
        idx = await client.get_namespace_index(uri)
20
        var = await client.nodes.root.get_child(["0:Objects", f"{idx}:MyObject", f"{idx}:MyVariable"])
21
22
        nb = 4000
23
        start = time.time()
24
        attr = ua.WriteValue()
25
        attr.NodeId = var.nodeid
26
        attr.AttributeId = ua.AttributeIds.Value
27
        attr.Value = ua.DataValue(ua.Variant(1.0, ua.VariantType.Float))
28
        params = ua.WriteParameters()
29
        params.NodesToWrite = [attr]
30
        for i in range(nb):
31
            params.NodesToWrite[0].Value.Value.Value = i
32
            result = await client.uaclient.write(params)
33
            #result[0].check()
34
            #await var.set_value(i)
35
    print("\n Write frequency: \n", nb / (time.time() - start))
36
37
if __name__ == '__main__':
38
    #uvloop.install()
39
    asyncio.run(main())
40
    #cProfile.run('asyncio.run(mymain(), debug=True)', filename="perf.cprof")
41