1212
1313# pylint: disable=line-too-long
1414
15+ from io import BytesIO
1516from datetime import datetime
1617from platform import python_version
1718from platform import version as osver
4647 b"s\x02 \xbb b8\xd7 !\xef \x10 [\x1e \x08 \xcc \xa4 \xc8 =\xfe \x91 \x16 F\xdf \xd6 \x87 \x07 \x86 \xba \xa8 \xeb \xa7 \xec \x8a \x93 \xa3 @\xab \xd1 \xcd Z<\xad \xf6 \xba L\xbe \xf5 \xd3 \xe7 \x14 \x91 \xa0 D$Q\xeb l\x1b t\xc6 \xa8 \x1e \xf3 \xe4 \x14 \xc4 \xd2 \x90 \xe4 \x9d \x1e \x87 \xee W\xff L\x8d \xbd \xa1 LxsK\xaf E\xb8 waU:\xbb 1m]\xbb e:\xbf '\xef +\xaf \xe3 j<\xe4 (]I\x01 \xe5 \x13 \xf8 \xf9 \x9d I\xf3 \xbe S\n +m\xc5 \xc0 Y\xfe \xb3 \x0f \x99 (9Th\xa4 \xb5 \x8e \xb7 t@\x91 F'\xaf \x16 (}\xee \xe0 ;\x1e \xd6 \xc1 \xe9 \xf7 V\x96 i@,%\xa7 \x19 ]Bc\xf4 ]z\x89 \xf8 \xb6 \xd4 \x91 RH!9`\r XB\xfa \xc7 \xf5 Q1n\xc8 \xcb \x9c \x92 \x19 \xcf i\x84 \x91 \xfc \xbb ~\x94 \xf5 \x15 61\xa5 3\xec =\x02 /\x9c \xd5 6\xe3 w\x00 \t T\xd7 =\x11 \x8e \x9f pf{\xed I\xc9 U\xa9 MM\xd0 %VbK[t\xe0 iz\xef d\x07 \xac *\xae \x0f \x9e \xe6 \xcb \xd8 \xcd l@\xca \x0c \xd4 \xd3 \xa6 \xbb \x8c \xc0 \n M~\xc6 >\xbd \x1a $B\x07 \xea \x8f \x17 b\xfe \xbb C\xc5 J\xd5 E9\x8e \xcf y\xe2 \xb9 \xf7 \x08 m:\x83 F2\xac \xe0 z\xd1 \x7f %\xca p\xe8 \xb6 TEl(P\" vY\xe4 \xe3 \x9d V\xa3 P\x16 \r \x92 \xcf \x11 \xc3 ;\x83 \xbb \x82 G}\x11 [\x86 p6\xab i\x03 t\xdd Y\x8e fV\xc2 \xb0 W2%\xb8 +\xb4 \xc2 ?@\xde \xff \x87 c\xec \xb8 .\xe0 \xcd W\x1a \xa8 \x10 3D\xff \xa6 @O\xba mJ\x04 \xf2 \xf0 \x8a \xc9 \x86 \xe3 " ,
4748 b"s\x02 \xd2 \xe3 8\xd7 !\xef \x10 [\x1e H\xd1 \xe1 \xcd \xb4 \xae \xbf \x97 \xe7 \xb5 \xbb A\xec \x9e _8*\x0c \xbf cOq^\xc7 h\x8c b\xd7 [\xec \xd1 \xee \x92 \xc4 \x16 \xeb \xef \x02 \x1b 9w\xd3 \x0e Ia\xb6 T\xa0 \x9c \xd2 \" \xc1 \x04 M[\x0b \x12 \xac %\x0c %y\x81 \xdf \x0e L\xe6 v\xe1 \xd1 \r f\x8c i\xe1 c\xed j\x7f \xdf \xad \xee |G\x9b l\xca b\x11 \x93 \x9a \x02 Oa=p{\xb4 <\xd1 \xd9 \xef \xd0 \x1a \xbc \xaa \xc4 \xa7 \xa2 \t \xf5 8\xcd \xb3 w>\xcb IC\x9d +\xf0 3q\xa3 \xf7 \xc7 K\xed /\xde D#[\x00 )\x07 Aiy\r t\x97 \xa0 \xa0 \xb8 \xbe \x81 L\xca '\x12 -K\xbe \xfc /]\xb4 \x92 \x12 \x9d \x8d ;\x9d K\xbe \xc7 \x18 \xad 7\x82 \xb7 \xae \xfa \x8c `m\xd5 M-M\xd6 D)\xfb \x12 9H3\xd5 U\xef A\x00 6\n \x1c \xb0 \xa1 \x05 \xc0 \xde Z\xd5 \xd4 3\xde xT\xfe *\x01 \xf6 \xaa +\x06 I\xdc \xc3 \xf6 H\xad \xb4 \xe5 \xdd \xf0 \xe7 \x0f Y\xc8 r\x0e \xa8 \xd4 nY\x0b \xae 0\xb3 D\x04 \xb9 b$\xc7 \xac V\xf5 \xba \xf7 7\xeb \xb0 \x90 \x07 \x07 \x18 z\xc3 \x92 W\x12 \x19 \x8d \xf3 W:\xa8 8#nQ\xb0 \xc8 \x14 \x03 \xf2 \xed \xcb 7\x0e \x05 \xf9 \xa3 \x17 }\xa1 \xba \xd8 \xd3 \\ /M9\r \x8b X(\xfa U\xce \xa1 \n \x07 \xe3 D~\xa7 \x9b \x1b \x01 \x08 \xa1 Dl9\x01 \xe2 \x99 *9\xd4 \xb1 \xdc \xc3 \xaa \xd0 \xb4 S\xb7 \xb8 \xa2 0\x80 \xad v=\xc5 \xc1 )\x06 jd\xea %\xaa ]\xb1 \xb7 \xb9 \xa0 \xe8 e\x88 M\xe9 ;AY\xed \xb8 \x1f \xdb \n Tx\xc6 \x99 \x96 Z\xae \x87 \x90 U\xbe \xeb \x08 \xcd \xec \xab \xf2 :\xdc \xf6 \xfb \xa1 zP>qtw\xeb \x19 \xca p \xf8 r0\x19 \xf2 \xb1 \x8c u\xbf \xa6 5\xef T9\xa7 +\xcf 8\xb1 \xba \x06 (\xc2 \xab " ,
4849]
50+ msgb = b""
51+ for msg in SPARTNMESSAGES :
52+ msgb += msg
53+ SPARTNBYTES = msgb
4954
5055
5156def progbar (i : int , lim : int , inc : int = 20 ):
@@ -66,24 +71,24 @@ def progbar(i: int, lim: int, inc: int = 20):
6671 )
6772
6873
69- def main (** kwargs ) -> float :
74+ def benchmark (** kwargs ) -> float :
7075 """
71- pyrtcm Performance benchmark test.
76+ pyspartn Performance benchmark test.
7277
7378 :param int cycles: (kwarg) number of test cycles (10,000)
7479 :returns: benchmark as transactions/second
7580 :rtype: float
76- :raises: UBXStreamError
81+ :raises: SPARTNStreamError
7782 """
7883
79- cyc = int (kwargs .get ("cycles" , 1000 ))
84+ cyc = int (kwargs .get ("cycles" , 5000 ))
8085 txnc = len (SPARTNMESSAGES )
8186 txnt = txnc * cyc
8287
8388 print (
8489 f"\n Operating system: { osver ()} " ,
8590 f"\n Python version: { python_version ()} " ,
86- f"\n pyrtcm version: { spartnver } " ,
91+ f"\n pyspartn version: { spartnver } " ,
8792 f"\n Test cycles: { cyc :,} " ,
8893 f"\n Txn per cycle: { txnc :,} " ,
8994 )
@@ -93,22 +98,33 @@ def main(**kwargs) -> float:
9398 print (f"\n Benchmark (decrypt={ decryptflag } ) test started at { start } " )
9499 for i in range (cyc ):
95100 progbar (i , cyc )
96- for msg in SPARTNMESSAGES :
97- _ = SPARTNReader . parse (
98- msg , decode = decryptflag , key = KEY , basedate = BASEDATE
99- )
101+ stream = BytesIO ( SPARTNBYTES )
102+ spr = SPARTNReader ( stream , decode = decryptflag , key = KEY , basedate = BASEDATE )
103+ for _ , _ in spr :
104+ pass
100105 end = process_time_ns ()
101106 print (f"Benchmark test ended at { end } ." )
102107 duration = end - start
103- rate = round (txnt * 1e9 / duration , 2 )
108+ msglen = len (SPARTNBYTES ) * cyc
109+ txs = round (txnt * 1e9 / duration , 2 )
110+ kbs = round (msglen * 1e9 / duration / 2 ** 10 , 2 )
104111
105112 print (
106- f"\n { txnt :,} messages processed in { duration / 1e9 :,.3f} seconds = { rate :,.2f} txns/second.\n "
113+ f"\n { txnt :,} messages processed in { duration / 1e9 :,.3f} seconds = { txs :,.2f} txns/second, { kbs :,.2f } kB /second.\n "
107114 )
108115
109- return rate
116+ return txs , kbs
110117
111118
112- if __name__ == "__main__" :
119+ def main ():
120+ """
121+ CLI Entry point.
122+
123+ args as benchmark() method
124+ """
113125
114- main (** dict (arg .split ("=" ) for arg in argv [1 :]))
126+ benchmark (** dict (arg .split ("=" ) for arg in argv [1 :]))
127+
128+
129+ if __name__ == "__main__" :
130+ main ()
0 commit comments