iptables -P INPUT DROP
iptables -P INPUT --dst x.x.x.x -j ACCEPT
import time
from math import tan, atan
D1 = dict()
D2 = dict()
D3 = dict()
NOTFOUND = object()
NNN = 100000
def long_calculation(x):
return atan(tan(x)/2)
def f1(x):
if x not in D1:
D1[x] = long_calculation(x)
return D1[x]
def f2(x):
try:
return D2[x]
except:
D2[x] = long_calculation(x)
return D2[x]
def f3(x):
result = D3.get(x, NOTFOUND)
if result is NOTFOUND:
result = D3[x] = long_calculation(x)
return result
t0 = time.time()
for j in range(0,NNN):
for x in range(0, 1000):
f1(x)
t1 = time.time()
for j in range(0, NNN):
for x in range(0, 1000):
f2(x)
t2 = time.time()
for j in range(0, NNN):
for x in range(0, 1000):
f3(x)
t3 = time.time()
print(t1-t0, t2 -t1, t3 -t2, sep="\n")
43.94197607040405
32.90516519546509
47.552075147628784
пятница... вечер...