Python 3.6.8 :: Anaconda, Inc. Use pyenv + virtualenv Ubuntu 18.04 (both laptop and server)
print statement is really slow
now = time.perf_counter() 
print(now) 
post = time.perf_counter() 
post2 = time.perf_counter() 
print(post-now) 
print(post2-post)
Result of turning with a stronger CPU on the server
3076898.47890643
0.00023056520149111748
3.0534807592630386e-05
Result of turning on a notebook PC (core i5 vPro 8th Gen)
144989.874304118
0.0001471959985792637
4.1409977711737156e-05
It takes time on the order of 100 to 200 microseconds.
The first time you enter a While statement is unusually slow ... the order is a few orders of magnitude different ... 1-100 microseconds can never be ignored (sometimes) ...
import time
now = time.perf_counter()  
print(now)  
print("1: ", time.perf_counter() - now)  
now = time.perf_counter()  
i = 0
print("2: ", time.perf_counter()-now)  
now = time.perf_counter()  
while(True):  
    print("3: ", time.perf_counter()-now)  
    i+ = 1  
    now = time.perf_counter()  
    if i > 10:  
        break
Result of turning with a stronger CPU on the server
3038070.24794605
1:  0.00013073207810521126
2:  4.219589754939079e-05
3:  4.715612158179283e-05
3:  4.00003045797348e-07
3:  2.752058207988739e-07
3:  2.169981598854065e-07
3:  2.1094456315040588e-07
3:  2.1280720829963684e-07
3:  2.05356627702713e-07
3:  2.1373853087425232e-07
3:  2.039596438407898e-07
3:  2.100132405757904e-07
3:  2.9010698199272156e-07
Result of turning on a notebook PC (core i5 vPro 8th Gen)
105718.03308281
1:  0.00013153199688531458
2:  0.00010217200906481594
3:  0.00010353099787607789
3:  7.040071068331599e-07
3:  3.370078047737479e-07
3:  3.1400122679769993e-07
3:  3.2399839255958796e-07
3:  3.2500247471034527e-07
3:  6.600021151825786e-07
3:  3.949971869587898e-07
3:  3.789900802075863e-07
3:  3.180030034855008e-07
3:  4.6400236897170544e-07
        Recommended Posts