PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/vb_suite/hdfstore_bench.py

https://github.com/hoffstein/pandas
Python | 278 lines | 276 code | 2 blank | 0 comment | 0 complexity | 44eea6373faa893b14e4bd8e5ac39307 MD5 | raw file
  1. from vbench.api import Benchmark
  2. from datetime import datetime
  3. start_date = datetime(2012, 7, 1)
  4. common_setup = """from .pandas_vb_common import *
  5. import os
  6. f = '__test__.h5'
  7. def remove(f):
  8. try:
  9. os.remove(f)
  10. except:
  11. pass
  12. """
  13. #----------------------------------------------------------------------
  14. # get from a store
  15. setup1 = common_setup + """
  16. index = tm.makeStringIndex(25000)
  17. df = DataFrame({'float1' : randn(25000),
  18. 'float2' : randn(25000)},
  19. index=index)
  20. remove(f)
  21. store = HDFStore(f)
  22. store.put('df1',df)
  23. """
  24. read_store = Benchmark("store.get('df1')", setup1, cleanup="store.close()",
  25. start_date=start_date)
  26. #----------------------------------------------------------------------
  27. # write to a store
  28. setup2 = common_setup + """
  29. index = tm.makeStringIndex(25000)
  30. df = DataFrame({'float1' : randn(25000),
  31. 'float2' : randn(25000)},
  32. index=index)
  33. remove(f)
  34. store = HDFStore(f)
  35. """
  36. write_store = Benchmark(
  37. "store.put('df2',df)", setup2, cleanup="store.close()",
  38. start_date=start_date)
  39. #----------------------------------------------------------------------
  40. # get from a store (mixed)
  41. setup3 = common_setup + """
  42. index = tm.makeStringIndex(25000)
  43. df = DataFrame({'float1' : randn(25000),
  44. 'float2' : randn(25000),
  45. 'string1' : ['foo'] * 25000,
  46. 'bool1' : [True] * 25000,
  47. 'int1' : np.random.randint(0, 250000, size=25000)},
  48. index=index)
  49. remove(f)
  50. store = HDFStore(f)
  51. store.put('df3',df)
  52. """
  53. read_store_mixed = Benchmark(
  54. "store.get('df3')", setup3, cleanup="store.close()",
  55. start_date=start_date)
  56. #----------------------------------------------------------------------
  57. # write to a store (mixed)
  58. setup4 = common_setup + """
  59. index = tm.makeStringIndex(25000)
  60. df = DataFrame({'float1' : randn(25000),
  61. 'float2' : randn(25000),
  62. 'string1' : ['foo'] * 25000,
  63. 'bool1' : [True] * 25000,
  64. 'int1' : np.random.randint(0, 250000, size=25000)},
  65. index=index)
  66. remove(f)
  67. store = HDFStore(f)
  68. """
  69. write_store_mixed = Benchmark(
  70. "store.put('df4',df)", setup4, cleanup="store.close()",
  71. start_date=start_date)
  72. #----------------------------------------------------------------------
  73. # get from a table (mixed)
  74. setup5 = common_setup + """
  75. N=10000
  76. index = tm.makeStringIndex(N)
  77. df = DataFrame({'float1' : randn(N),
  78. 'float2' : randn(N),
  79. 'string1' : ['foo'] * N,
  80. 'bool1' : [True] * N,
  81. 'int1' : np.random.randint(0, N, size=N)},
  82. index=index)
  83. remove(f)
  84. store = HDFStore(f)
  85. store.append('df5',df)
  86. """
  87. read_store_table_mixed = Benchmark(
  88. "store.select('df5')", setup5, cleanup="store.close()",
  89. start_date=start_date)
  90. #----------------------------------------------------------------------
  91. # write to a table (mixed)
  92. setup6 = common_setup + """
  93. index = tm.makeStringIndex(25000)
  94. df = DataFrame({'float1' : randn(25000),
  95. 'float2' : randn(25000),
  96. 'string1' : ['foo'] * 25000,
  97. 'bool1' : [True] * 25000,
  98. 'int1' : np.random.randint(0, 25000, size=25000)},
  99. index=index)
  100. remove(f)
  101. store = HDFStore(f)
  102. """
  103. write_store_table_mixed = Benchmark(
  104. "store.append('df6',df)", setup6, cleanup="store.close()",
  105. start_date=start_date)
  106. #----------------------------------------------------------------------
  107. # select from a table
  108. setup7 = common_setup + """
  109. index = tm.makeStringIndex(25000)
  110. df = DataFrame({'float1' : randn(25000),
  111. 'float2' : randn(25000) },
  112. index=index)
  113. remove(f)
  114. store = HDFStore(f)
  115. store.append('df7',df)
  116. """
  117. read_store_table = Benchmark(
  118. "store.select('df7')", setup7, cleanup="store.close()",
  119. start_date=start_date)
  120. #----------------------------------------------------------------------
  121. # write to a table
  122. setup8 = common_setup + """
  123. index = tm.makeStringIndex(25000)
  124. df = DataFrame({'float1' : randn(25000),
  125. 'float2' : randn(25000) },
  126. index=index)
  127. remove(f)
  128. store = HDFStore(f)
  129. """
  130. write_store_table = Benchmark(
  131. "store.append('df8',df)", setup8, cleanup="store.close()",
  132. start_date=start_date)
  133. #----------------------------------------------------------------------
  134. # get from a table (wide)
  135. setup9 = common_setup + """
  136. df = DataFrame(np.random.randn(25000,100))
  137. remove(f)
  138. store = HDFStore(f)
  139. store.append('df9',df)
  140. """
  141. read_store_table_wide = Benchmark(
  142. "store.select('df9')", setup9, cleanup="store.close()",
  143. start_date=start_date)
  144. #----------------------------------------------------------------------
  145. # write to a table (wide)
  146. setup10 = common_setup + """
  147. df = DataFrame(np.random.randn(25000,100))
  148. remove(f)
  149. store = HDFStore(f)
  150. """
  151. write_store_table_wide = Benchmark(
  152. "store.append('df10',df)", setup10, cleanup="store.close()",
  153. start_date=start_date)
  154. #----------------------------------------------------------------------
  155. # get from a table (wide)
  156. setup11 = common_setup + """
  157. index = date_range('1/1/2000', periods = 25000)
  158. df = DataFrame(np.random.randn(25000,100), index = index)
  159. remove(f)
  160. store = HDFStore(f)
  161. store.append('df11',df)
  162. """
  163. query_store_table_wide = Benchmark(
  164. "store.select('df11', [ ('index', '>', df.index[10000]), ('index', '<', df.index[15000]) ])", setup11, cleanup="store.close()",
  165. start_date=start_date)
  166. #----------------------------------------------------------------------
  167. # query from a table
  168. setup12 = common_setup + """
  169. index = date_range('1/1/2000', periods = 25000)
  170. df = DataFrame({'float1' : randn(25000),
  171. 'float2' : randn(25000) },
  172. index=index)
  173. remove(f)
  174. store = HDFStore(f)
  175. store.append('df12',df)
  176. """
  177. query_store_table = Benchmark(
  178. "store.select('df12', [ ('index', '>', df.index[10000]), ('index', '<', df.index[15000]) ])", setup12, cleanup="store.close()",
  179. start_date=start_date)
  180. #----------------------------------------------------------------------
  181. # select from a panel table
  182. setup13 = common_setup + """
  183. p = Panel(randn(20, 1000, 25), items= [ 'Item%03d' % i for i in range(20) ],
  184. major_axis=date_range('1/1/2000', periods=1000), minor_axis = [ 'E%03d' % i for i in range(25) ])
  185. remove(f)
  186. store = HDFStore(f)
  187. store.append('p1',p)
  188. """
  189. read_store_table_panel = Benchmark(
  190. "store.select('p1')", setup13, cleanup="store.close()",
  191. start_date=start_date)
  192. #----------------------------------------------------------------------
  193. # write to a panel table
  194. setup14 = common_setup + """
  195. p = Panel(randn(20, 1000, 25), items= [ 'Item%03d' % i for i in range(20) ],
  196. major_axis=date_range('1/1/2000', periods=1000), minor_axis = [ 'E%03d' % i for i in range(25) ])
  197. remove(f)
  198. store = HDFStore(f)
  199. """
  200. write_store_table_panel = Benchmark(
  201. "store.append('p2',p)", setup14, cleanup="store.close()",
  202. start_date=start_date)
  203. #----------------------------------------------------------------------
  204. # write to a table (data_columns)
  205. setup15 = common_setup + """
  206. df = DataFrame(np.random.randn(10000,10),columns = [ 'C%03d' % i for i in range(10) ])
  207. remove(f)
  208. store = HDFStore(f)
  209. """
  210. write_store_table_dc = Benchmark(
  211. "store.append('df15',df,data_columns=True)", setup15, cleanup="store.close()",
  212. start_date=start_date)