fork(2) download
  1. import timeit
  2. import numpy
  3.  
  4. print(numpy.version.version)
  5. print()
  6.  
  7. x = numpy.array([True])
  8.  
  9. print('Small input:')
  10. print(timeit.timeit('x.any()', globals=globals(), number=1000))
  11. print(timeit.timeit('x.max()', globals=globals(), number=1000))
  12. print(timeit.timeit('x[x.argmax()]', globals=globals(), number=1000))
  13. print()
  14.  
  15. x = numpy.zeros(10000000, dtype=bool)
  16.  
  17. print('Large input, all False:')
  18. print(timeit.timeit('x.any()', globals=globals(), number=1000))
  19. print(timeit.timeit('x.max()', globals=globals(), number=1000))
  20. print(timeit.timeit('x[x.argmax()]', globals=globals(), number=1000))
  21. print()
  22.  
  23. x[0] = True
  24.  
  25. print('Large input, leading True:')
  26. print(timeit.timeit('x.any()', globals=globals(), number=1000))
  27. print(timeit.timeit('x.max()', globals=globals(), number=1000))
  28. print(timeit.timeit('x[x.argmax()]', globals=globals(), number=1000))
Success #stdin #stdout 1.38s 93248KB
stdin
Standard input is empty
stdout
1.12.0

Small input:
0.0011177989654242992
0.000862916000187397
0.00035959482192993164

Large input, all False:
0.32091754395514727
0.3793730647303164
0.2158978171646595

Large input, leading True:
0.3196195405907929
0.07680606096982956
0.00036822492256760597