Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / test-suite / python / python_pybuf_runme3.py
1 #run: 
2 #  python python_pybuf_runme3.py benchmark
3 #for the benchmark, other wise the test case will be run
4 import python_pybuf
5 import sys
6 if len(sys.argv)>=2 and sys.argv[1]=="benchmark":
7     #run the benchmark
8     import time
9     k=1000000 #number of times to excute the functions
10
11     t=time.time()
12     a = bytearray(b'hello world')
13     for i in range(k):
14       pybuf.title1(a)
15     print("Time used by bytearray:",time.time()-t)
16
17     t=time.time()
18     b = 'hello world'
19     for i in range(k):
20       pybuf.title2(b)
21     print("Time used by string:",time.time()-t)
22 else:
23     #run the test case
24     buf1 = bytearray(10)
25     buf2 = bytearray(50)
26
27     pybuf.func1(buf1)
28     assert buf1 == b'a'*10
29
30     pybuf.func2(buf2)
31     assert buf2.startswith(b"Hello world!\x00")
32
33     count = pybuf.func3(buf2)
34     assert count==10 #number of alpha and number in 'Hello world!'
35
36     length = pybuf.func4(buf2)
37     assert length==12
38
39     buf3 = bytearray(b"hello")
40     pybuf.title1(buf3)
41     assert buf3==b'Hello'
42