Synergy – pracuj wygodniej
3 tyg. temu
czyli co w obiektywie piszczy i w komputerze szumi
def test(request):
return HttpResponse('<html>Hello!</html>')
Total transferred: 152000 bytes
HTML transferred: 19000 bytes
Requests per second: 961.41 [#/sec] (mean)
Time per request: 1.040 [ms] (mean)
Time per request: 1.040 [ms] (mean, across all concurrent requests)
Transfer rate: 142.71 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1 1 0.8 1 22
Waiting: 0 1 0.8 1 21
Total: 1 1 0.8 1 22
def test(request):
wal = Waluta.objects.get(pk='USD')
return HttpResponse('<html>Hello! - %s</html>' % wal.nazwa)
Total transferred: 173000 bytes
HTML transferred: 40000 bytes
Requests per second: 130.48 [#/sec] (mean)
Time per request: 7.664 [ms] (mean)
Time per request: 7.664 [ms] (mean, across all concurrent requests)
Transfer rate: 22.04 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 6 8 1.4 7 19
Waiting: 4 7 1.4 7 18
Total: 6 8 1.4 7 19
def test(request):
wal = Waluta.objects.get(pk='USD')
wartosc = WartoscWaluty.objects.get(waluta=wal)
kurs = wartosc.kurs
return HttpResponse('<html>Hello! - %s</html>' % kurs)
Total transferred: 182000 bytes
HTML transferred: 49000 bytes
Requests per second: 91.41 [#/sec] (mean)
Time per request: 10.940 [ms] (mean)
Time per request: 10.940 [ms] (mean, across all concurrent requests)
Transfer rate: 16.25 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 9 11 1.4 11 25
Waiting: 8 10 1.3 10 24
Total: 9 11 1.4 11 25
@cache_page(60*15)
def test(request):
wal = Waluta.objects.get(pk='USD')
wartosc = WartoscWaluty.objects.get(waluta=wal)
kurs = wartosc.kurs
return HttpResponse('<html>Hello! - %s</html>' % kurs)
Total transferred: 338000 bytes
HTML transferred: 49000 bytes
Requests per second: 605.64 [#/sec] (mean)
Time per request: 1.651 [ms] (mean)
Time per request: 1.651 [ms] (mean, across all concurrent requests)
Transfer rate: 199.91 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1 2 1.2 1 33
Waiting: 1 1 1.2 1 32
Total: 1 2 1.2 1 33
#!/usr/bin/env python
from threading import Thread
class moj_watek(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
a = 1
while(1): a+=a/2
watek = moj_watek()
watek.start()
b = 1
while 1: b+=b/2

import sys
import os
import gc
import types
import inspect
import atexit
def check_allocations():
dt = {}
#gc.collect() jeśli byśmy chcieli info tylko o obiektach żyjących
for obj in gc.get_objects():
try:
if dt.has_key(obj.__class__.__name__):
instances,number,size,typ,bi,module = dt[obj.__class__.__name__]
number+=1
size+=sys.getsizeof(obj)
if obj not in instances:
instances.append(obj)
dt[obj.__class__.__name__] = (instances,number,size,typ,bi,module)
else:
dt[obj.__class__.__name__] = ([obj],1,sys.getsizeof(obj),type(obj),inspect.isbuiltin(obj),obj.__module__)
except AttributeError as e:
pass
return dt
def run():
data = check_allocations()
print '\n\nCurrent allocations'
print '\t%40s | %9s | %9s bytes | <<%s>>' % ('Class name', 'number', 'size', 'module')
print '\t-----------------------------------------------------------------------------------'
for key in data:
instcs,number,size,typ,bi,module = data[key]
if module == '__main__':
print '\t%-40.40s | %9d | %9d bytes | <<%s>>' % (key, number, size, module)
for inst in instcs:
print '\t -> %14.14s 0x%016x | %9s | %9s bytes | <<%s>>' % ('id', id(inst),' ',sys.getsizeof(inst),'---')
print gc.garbage
print '\n\n'
def main():
import os, sys
from optparse import OptionParser
usage = "profiler.py scriptfile"
parser = OptionParser(usage=usage)
parser.allow_interspersed_args = False
if not sys.argv[1:]:
parser.print_usage()
sys.exit(2)
(options,args) = parser.parse_args()
sys.argv[:] = args
if len(sys.argv) > 0:
import __main__
dict = __main__.__dict__
sys.path.insert(0, os.path.dirname(sys.argv[0]))
gc.set_threshold(0)
gc.set_debug(gc.DEBUG_SAVEALL)
try:
exec 'execfile(%r)' % sys.argv[0] in dict, dict
except KeyboardInterrupt as ki:
pass
atexit.register(run)
else:
parser.print_usage()
if __name__ == '__main__':
main()
python -m profiler monitorowany_skrypt.py