-
Notifications
You must be signed in to change notification settings - Fork 647
/
arithmetic_benchmark.py
56 lines (40 loc) · 1.75 KB
/
arithmetic_benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging
import argparse
import ray
import os
import modin.pandas as pd
from utils import time_logger
parser = argparse.ArgumentParser(description="arithmetic benchmark")
parser.add_argument("--path", dest="path", help="path to the csv data file")
parser.add_argument("--logfile", dest="logfile", help="path to the log file")
args = parser.parse_args()
file = args.path
file_size = os.path.getsize(file)
if not os.path.exists(os.path.split(args.logfile)[0]):
os.makedirs(os.path.split(args.logfile)[0])
logging.basicConfig(filename=args.logfile, level=logging.INFO)
df = pd.read_csv(file)
blocks = df._block_partitions.flatten().tolist()
ray.wait(blocks, len(blocks))
with time_logger("Transpose: {}; Size: {} bytes".format(file, file_size)):
blocks = df.T.flatten().tolist()
ray.wait(blocks, len(blocks))
with time_logger("Sum on axis=0: {}; Size: {} bytes".format(file, file_size)):
df.sum()
with time_logger("Sum on axis=1: {}; Size: {} bytes".format(file, file_size)):
df.sum(axis=1)
with time_logger("Median on axis=0: {}; Size: {} bytes".format(file, file_size)):
df.median()
with time_logger("Median on axis=1: {}; Size: {} bytes".format(file, file_size)):
df.median(axis=1)
with time_logger("nunique on axis=0: {}; Size: {} bytes".format(file, file_size)):
df.nunique()
with time_logger("nunique on axis=1: {}; Size: {} bytes".format(file, file_size)):
df.nunique(axis=1)
with time_logger("Sum UDF on axis=0: {}; Size: {} bytes".format(file, file_size)):
df.apply(lambda df: df.sum())
with time_logger("Sum UDF on axis=1: {}; Size: {} bytes".format(file, file_size)):
df.apply(lambda df: df.sum(), axis=1)