Skip to content

Commit 37f29e5

Browse files
authored
Expanded ASVs for to_json (pandas-dev#27595)
1 parent 619f52b commit 37f29e5

File tree

1 file changed

+72
-18
lines changed

1 file changed

+72
-18
lines changed

asv_bench/benchmarks/io/json.py

+72-18
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ def peakmem_read_json_lines_concat(self, index):
6363
class ToJSON(BaseIO):
6464

6565
fname = "__test__.json"
66-
params = ["split", "columns", "index"]
67-
param_names = ["orient"]
66+
params = [
67+
["split", "columns", "index", "values", "records"],
68+
["df", "df_date_idx", "df_td_int_ts", "df_int_floats", "df_int_float_str"],
69+
]
70+
param_names = ["orient", "frame"]
6871

69-
def setup(self, lines_orient):
72+
def setup(self, orient, frame):
7073
N = 10 ** 5
7174
ncols = 5
7275
index = date_range("20000101", periods=N, freq="H")
@@ -111,34 +114,85 @@ def setup(self, lines_orient):
111114
index=index,
112115
)
113116

114-
def time_floats_with_int_index(self, orient):
115-
self.df.to_json(self.fname, orient=orient)
117+
def time_to_json(self, orient, frame):
118+
getattr(self, frame).to_json(self.fname, orient=orient)
116119

117-
def time_floats_with_dt_index(self, orient):
118-
self.df_date_idx.to_json(self.fname, orient=orient)
120+
def mem_to_json(self, orient, frame):
121+
getattr(self, frame).to_json(self.fname, orient=orient)
122+
123+
def time_to_json_wide(self, orient, frame):
124+
base_df = getattr(self, frame).copy()
125+
df = concat([base_df.iloc[:100]] * 1000, ignore_index=True, axis=1)
126+
df.to_json(self.fname, orient=orient)
127+
128+
def mem_to_json_wide(self, orient, frame):
129+
base_df = getattr(self, frame).copy()
130+
df = concat([base_df.iloc[:100]] * 1000, ignore_index=True, axis=1)
131+
df.to_json(self.fname, orient=orient)
119132

120-
def time_delta_int_tstamp(self, orient):
121-
self.df_td_int_ts.to_json(self.fname, orient=orient)
122133

123-
def time_float_int(self, orient):
124-
self.df_int_floats.to_json(self.fname, orient=orient)
134+
class ToJSONLines(BaseIO):
125135

126-
def time_float_int_str(self, orient):
127-
self.df_int_float_str.to_json(self.fname, orient=orient)
136+
fname = "__test__.json"
137+
138+
def setup(self):
139+
N = 10 ** 5
140+
ncols = 5
141+
index = date_range("20000101", periods=N, freq="H")
142+
timedeltas = timedelta_range(start=1, periods=N, freq="s")
143+
datetimes = date_range(start=1, periods=N, freq="s")
144+
ints = np.random.randint(100000000, size=N)
145+
floats = np.random.randn(N)
146+
strings = tm.makeStringIndex(N)
147+
self.df = DataFrame(np.random.randn(N, ncols), index=np.arange(N))
148+
self.df_date_idx = DataFrame(np.random.randn(N, ncols), index=index)
149+
self.df_td_int_ts = DataFrame(
150+
{
151+
"td_1": timedeltas,
152+
"td_2": timedeltas,
153+
"int_1": ints,
154+
"int_2": ints,
155+
"ts_1": datetimes,
156+
"ts_2": datetimes,
157+
},
158+
index=index,
159+
)
160+
self.df_int_floats = DataFrame(
161+
{
162+
"int_1": ints,
163+
"int_2": ints,
164+
"int_3": ints,
165+
"float_1": floats,
166+
"float_2": floats,
167+
"float_3": floats,
168+
},
169+
index=index,
170+
)
171+
self.df_int_float_str = DataFrame(
172+
{
173+
"int_1": ints,
174+
"int_2": ints,
175+
"float_1": floats,
176+
"float_2": floats,
177+
"str_1": strings,
178+
"str_2": strings,
179+
},
180+
index=index,
181+
)
128182

129-
def time_floats_with_int_idex_lines(self, orient):
183+
def time_floats_with_int_idex_lines(self):
130184
self.df.to_json(self.fname, orient="records", lines=True)
131185

132-
def time_floats_with_dt_index_lines(self, orient):
186+
def time_floats_with_dt_index_lines(self):
133187
self.df_date_idx.to_json(self.fname, orient="records", lines=True)
134188

135-
def time_delta_int_tstamp_lines(self, orient):
189+
def time_delta_int_tstamp_lines(self):
136190
self.df_td_int_ts.to_json(self.fname, orient="records", lines=True)
137191

138-
def time_float_int_lines(self, orient):
192+
def time_float_int_lines(self):
139193
self.df_int_floats.to_json(self.fname, orient="records", lines=True)
140194

141-
def time_float_int_str_lines(self, orient):
195+
def time_float_int_str_lines(self):
142196
self.df_int_float_str.to_json(self.fname, orient="records", lines=True)
143197

144198

0 commit comments

Comments
 (0)