@@ -19,7 +19,7 @@ from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
19
19
20
20
name = os .path .basename (__file__ )
21
21
22
- InsertStat = namedtuple ('InsertStat' ,'start_at end_at tps cost_time' )
22
+ InsertStat = namedtuple ('InsertStat' ,'start_at end_at rows cost_time' )
23
23
24
24
def parser_cmd_args ():
25
25
"""
@@ -74,28 +74,31 @@ def insert(host="127.0.0.1",port=3306,user="apuser",password="mtls@0352",databas
74
74
end_at = datetime .now ()
75
75
76
76
# 微秒级的精度
77
- cost_time = (end_at - start_at ).microseconds
78
- tps = (rows / cost_time ) * 1000000
79
- stat = InsertStat (start_at = start_at ,end_at = end_at ,tps = tps ,cost_time = cost_time / 1000000 )
77
+ cost_time = (end_at - start_at ).total_seconds ()
78
+ stat = InsertStat (start_at = start_at ,end_at = end_at ,rows = rows ,cost_time = cost_time )
80
79
return stat
81
80
82
81
def create_report (stats :InsertStat = None ):
83
82
"""
84
83
"""
85
84
assert stats is not None
86
- sum_tps = 0
85
+ sum_rows = 0
87
86
sum_cost_time = 0
88
87
for s in stats :
89
- if hasattr (s ,'tps ' ):
90
- sum_tps = sum_tps + s .tps
88
+ if hasattr (s ,'rows ' ):
89
+ sum_rows = sum_rows + s .rows
91
90
sum_cost_time = sum_cost_time + s .cost_time
92
91
93
- tps = sum_tps / len (stats )
94
- cost_time = sum_cost_time / len (stats )
92
+ avg_cost_time = sum_cost_time / len (stats )
93
+
94
+ if avg_cost_time == 0 :
95
+ # 后面 avg_cost_time 要做为分母,所以当这个值是 0 的时候把它设置为 1
96
+ avg_cost_time = 1
97
+ tps = sum_rows / avg_cost_time
95
98
96
99
print ("-" * 36 )
97
100
print (f"|tps = { tps } " )
98
- print (f"|cost_time = { cost_time } " )
101
+ print (f"|cost_time = { avg_cost_time } " )
99
102
print ("-" * 36 )
100
103
101
104
0 commit comments