PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vb_suite/binary_ops.py

http://github.com/wesm/pandas
Python | 199 lines | 198 code | 1 blank | 0 comment | 0 complexity | d88fceec1a49222fd74f6b1a3130d055 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. from vbench.benchmark import Benchmark
  2. from datetime import datetime
  3. common_setup = """from .pandas_vb_common import *
  4. """
  5. SECTION = 'Binary ops'
  6. #----------------------------------------------------------------------
  7. # binary ops
  8. #----------------------------------------------------------------------
  9. # add
  10. setup = common_setup + """
  11. df = DataFrame(np.random.randn(20000, 100))
  12. df2 = DataFrame(np.random.randn(20000, 100))
  13. """
  14. frame_add = \
  15. Benchmark("df + df2", setup, name='frame_add',
  16. start_date=datetime(2012, 1, 1))
  17. setup = common_setup + """
  18. import pandas.computation.expressions as expr
  19. df = DataFrame(np.random.randn(20000, 100))
  20. df2 = DataFrame(np.random.randn(20000, 100))
  21. expr.set_numexpr_threads(1)
  22. """
  23. frame_add_st = \
  24. Benchmark("df + df2", setup, name='frame_add_st',cleanup="expr.set_numexpr_threads()",
  25. start_date=datetime(2013, 2, 26))
  26. setup = common_setup + """
  27. import pandas.computation.expressions as expr
  28. df = DataFrame(np.random.randn(20000, 100))
  29. df2 = DataFrame(np.random.randn(20000, 100))
  30. expr.set_use_numexpr(False)
  31. """
  32. frame_add_no_ne = \
  33. Benchmark("df + df2", setup, name='frame_add_no_ne',cleanup="expr.set_use_numexpr(True)",
  34. start_date=datetime(2013, 2, 26))
  35. #----------------------------------------------------------------------
  36. # mult
  37. setup = common_setup + """
  38. df = DataFrame(np.random.randn(20000, 100))
  39. df2 = DataFrame(np.random.randn(20000, 100))
  40. """
  41. frame_mult = \
  42. Benchmark("df * df2", setup, name='frame_mult',
  43. start_date=datetime(2012, 1, 1))
  44. setup = common_setup + """
  45. import pandas.computation.expressions as expr
  46. df = DataFrame(np.random.randn(20000, 100))
  47. df2 = DataFrame(np.random.randn(20000, 100))
  48. expr.set_numexpr_threads(1)
  49. """
  50. frame_mult_st = \
  51. Benchmark("df * df2", setup, name='frame_mult_st',cleanup="expr.set_numexpr_threads()",
  52. start_date=datetime(2013, 2, 26))
  53. setup = common_setup + """
  54. import pandas.computation.expressions as expr
  55. df = DataFrame(np.random.randn(20000, 100))
  56. df2 = DataFrame(np.random.randn(20000, 100))
  57. expr.set_use_numexpr(False)
  58. """
  59. frame_mult_no_ne = \
  60. Benchmark("df * df2", setup, name='frame_mult_no_ne',cleanup="expr.set_use_numexpr(True)",
  61. start_date=datetime(2013, 2, 26))
  62. #----------------------------------------------------------------------
  63. # division
  64. setup = common_setup + """
  65. df = DataFrame(np.random.randn(1000, 1000))
  66. """
  67. frame_float_div_by_zero = \
  68. Benchmark("df / 0", setup, name='frame_float_div_by_zero')
  69. setup = common_setup + """
  70. df = DataFrame(np.random.randn(1000, 1000))
  71. """
  72. frame_float_floor_by_zero = \
  73. Benchmark("df // 0", setup, name='frame_float_floor_by_zero')
  74. setup = common_setup + """
  75. df = DataFrame(np.random.random_integers(np.iinfo(np.int16).min, np.iinfo(np.int16).max, size=(1000, 1000)))
  76. """
  77. frame_int_div_by_zero = \
  78. Benchmark("df / 0", setup, name='frame_int_div_by_zero')
  79. setup = common_setup + """
  80. df = DataFrame(np.random.randn(1000, 1000))
  81. df2 = DataFrame(np.random.randn(1000, 1000))
  82. """
  83. frame_float_div = \
  84. Benchmark("df // df2", setup, name='frame_float_div')
  85. #----------------------------------------------------------------------
  86. # modulo
  87. setup = common_setup + """
  88. df = DataFrame(np.random.randn(1000, 1000))
  89. df2 = DataFrame(np.random.randn(1000, 1000))
  90. """
  91. frame_float_mod = \
  92. Benchmark("df / df2", setup, name='frame_float_mod')
  93. setup = common_setup + """
  94. df = DataFrame(np.random.random_integers(np.iinfo(np.int16).min, np.iinfo(np.int16).max, size=(1000, 1000)))
  95. df2 = DataFrame(np.random.random_integers(np.iinfo(np.int16).min, np.iinfo(np.int16).max, size=(1000, 1000)))
  96. """
  97. frame_int_mod = \
  98. Benchmark("df / df2", setup, name='frame_int_mod')
  99. #----------------------------------------------------------------------
  100. # multi and
  101. setup = common_setup + """
  102. df = DataFrame(np.random.randn(20000, 100))
  103. df2 = DataFrame(np.random.randn(20000, 100))
  104. """
  105. frame_multi_and = \
  106. Benchmark("df[(df>0) & (df2>0)]", setup, name='frame_multi_and',
  107. start_date=datetime(2012, 1, 1))
  108. setup = common_setup + """
  109. import pandas.computation.expressions as expr
  110. df = DataFrame(np.random.randn(20000, 100))
  111. df2 = DataFrame(np.random.randn(20000, 100))
  112. expr.set_numexpr_threads(1)
  113. """
  114. frame_multi_and_st = \
  115. Benchmark("df[(df>0) & (df2>0)]", setup, name='frame_multi_and_st',cleanup="expr.set_numexpr_threads()",
  116. start_date=datetime(2013, 2, 26))
  117. setup = common_setup + """
  118. import pandas.computation.expressions as expr
  119. df = DataFrame(np.random.randn(20000, 100))
  120. df2 = DataFrame(np.random.randn(20000, 100))
  121. expr.set_use_numexpr(False)
  122. """
  123. frame_multi_and_no_ne = \
  124. Benchmark("df[(df>0) & (df2>0)]", setup, name='frame_multi_and_no_ne',cleanup="expr.set_use_numexpr(True)",
  125. start_date=datetime(2013, 2, 26))
  126. #----------------------------------------------------------------------
  127. # timeseries
  128. setup = common_setup + """
  129. N = 1000000
  130. halfway = N // 2 - 1
  131. s = Series(date_range('20010101', periods=N, freq='T'))
  132. ts = s[halfway]
  133. """
  134. timestamp_series_compare = Benchmark("ts >= s", setup,
  135. start_date=datetime(2013, 9, 27))
  136. series_timestamp_compare = Benchmark("s <= ts", setup,
  137. start_date=datetime(2012, 2, 21))
  138. setup = common_setup + """
  139. N = 1000000
  140. s = Series(date_range('20010101', periods=N, freq='s'))
  141. """
  142. timestamp_ops_diff1 = Benchmark("s.diff()", setup,
  143. start_date=datetime(2013, 1, 1))
  144. timestamp_ops_diff2 = Benchmark("s-s.shift()", setup,
  145. start_date=datetime(2013, 1, 1))
  146. #----------------------------------------------------------------------
  147. # timeseries with tz
  148. setup = common_setup + """
  149. N = 10000
  150. halfway = N // 2 - 1
  151. s = Series(date_range('20010101', periods=N, freq='T', tz='US/Eastern'))
  152. ts = s[halfway]
  153. """
  154. timestamp_tz_series_compare = Benchmark("ts >= s", setup,
  155. start_date=datetime(2013, 9, 27))
  156. series_timestamp_tz_compare = Benchmark("s <= ts", setup,
  157. start_date=datetime(2012, 2, 21))
  158. setup = common_setup + """
  159. N = 10000
  160. s = Series(date_range('20010101', periods=N, freq='s', tz='US/Eastern'))
  161. """
  162. timestamp_tz_ops_diff1 = Benchmark("s.diff()", setup,
  163. start_date=datetime(2013, 1, 1))
  164. timestamp_tz_ops_diff2 = Benchmark("s-s.shift()", setup,
  165. start_date=datetime(2013, 1, 1))