From f7d2a063710f33feb8edbac8ac94dd8f7730e0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Sat, 16 Jan 2021 23:15:24 +0800 Subject: [PATCH] spppppeed teeeeest! --- libs/P_C.py | 6 +----- libs/tools.py | 23 ----------------------- test_speed.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 test_speed.py diff --git a/libs/P_C.py b/libs/P_C.py index df1a449..2e17ba8 100644 --- a/libs/P_C.py +++ b/libs/P_C.py @@ -7,11 +7,7 @@ file name stand for : Physics calculation import libs import math - -F_A = libs.tools.F_A() -F_D = libs.tools.F_D() -F_Mi = libs.tools.F_Mi() -F_Mu = libs.tools.F_mu() +from decimal import Decimal as D def S_C_float_check(SC): # stand for Scientific notation's float check diff --git a/libs/tools.py b/libs/tools.py index b914228..0dfafc1 100644 --- a/libs/tools.py +++ b/libs/tools.py @@ -33,26 +33,3 @@ def D_C(listA, listB): # stand for Duplicate check listB.sort() return - -def F_Mu(A, B): # stand for float multiple - a = decimal.Decimal(str(A)) - b = decimal.Decimal(str(B)) - return float(a * b) - - -def F_D(A, B): # stand for float divided - a = decimal.Decimal(str(A)) - b = decimal.Decimal(str(B)) - return float(a / b) - - -def F_A(A, B): # stand for float plus - a = decimal.Decimal(str(A)) - b = decimal.Decimal(str(B)) - return float(a + b) - - -def F_Mi(A, B): # stand for float minus - a = decimal.Decimal(str(A)) - b = decimal.Decimal(str(B)) - return float(a - b) diff --git a/test_speed.py b/test_speed.py new file mode 100644 index 0000000..2f74f61 --- /dev/null +++ b/test_speed.py @@ -0,0 +1,42 @@ +import time + +from decimal import Decimal as D + + +times = 1000000 + +a = 1 +b = 2 + +c = 0.1 +d = 2.1 + +a_start_time = time.time() +for x in range(0, times, 1): + Da = D(str(a)) + Db = D(str(b)) + Dc = Da * Db +a_stop_time = time.time() + +b_start_time = time.time() +Da = D(str(a)) +Db = D(str(b)) +for x in range(0, times, 1): + Dc = Da * Db +b_stop_time = time.time() + +c_start_time = time.time() +for x in range(0, times, 1): + Tc = a * b +c_stop_time = time.time() + +def test(times, a, b): + t = times + s = time.time() + while t: + + t -= 1 + e = time.time() + return e - s + +