fork(12) download
  1. # http://es.stackoverflow.com/q/23328/127
  2. import cProfile, pstats, io, string
  3. from random import randint, choice
  4.  
  5. semilla = 'valor'
  6. val = semilla + ' a comparar'
  7.  
  8. def ne(x):
  9. if x != val:
  10. pass
  11.  
  12. def en(x):
  13. if not x == val:
  14. pass
  15.  
  16. def ee(x):
  17. if x == val:
  18. pass
  19. else:
  20. pass
  21.  
  22. def rndx():
  23. if ( randint(0,1)==0 ):
  24. return val
  25. else:
  26. return semilla + ''.join(choice(val) for i in range(randint(1,20)))
  27.  
  28.  
  29. x = val
  30. pr = cProfile.Profile()
  31. pr.enable()
  32. for i in range(2000000):
  33. if (i % 10000 == 0):
  34. x = rndx()
  35. en(x)
  36. ee(x)
  37. ne(x)
  38. pr.disable()
  39. s = io.StringIO()
  40. sortby = 'cumulative'
  41. ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
  42. ps.print_stats()
  43. print(s.getvalue())
Success #stdin #stdout 10.96s 13544KB
stdin
Standard input is empty
stdout
         6009740 function calls in 4.804 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  2000000    1.609    0.000    1.609    0.000 ./prog.py:12(en)
  2000000    1.587    0.000    1.587    0.000 ./prog.py:16(ee)
  2000000    1.583    0.000    1.583    0.000 ./prog.py:8(ne)
      200    0.002    0.000    0.024    0.000 ./prog.py:22(rndx)
      105    0.002    0.000    0.016    0.000 {method 'join' of 'str' objects}
     1189    0.002    0.000    0.014    0.000 ./prog.py:26(<genexpr>)
     1084    0.004    0.000    0.012    0.000 /usr/lib/python3.4/random.py:250(choice)
     1389    0.007    0.000    0.010    0.000 /usr/lib/python3.4/random.py:220(_randbelow)
      305    0.001    0.000    0.006    0.000 /usr/lib/python3.4/random.py:214(randint)
      305    0.002    0.000    0.005    0.000 /usr/lib/python3.4/random.py:170(randrange)
     2689    0.003    0.000    0.003    0.000 {method 'getrandbits' of '_random.Random' objects}
     1389    0.001    0.000    0.001    0.000 {method 'bit_length' of 'int' objects}
     1084    0.001    0.000    0.001    0.000 {built-in method len}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}