Skip to content

Commit

Permalink
Added polars_performance.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Nov 9, 2023
1 parent 742f95b commit d3f3122
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
43 changes: 22 additions & 21 deletions benchmarks/dataframe_performance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,54 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <DataFrame/DataFrameStatsVisitors.h>
#include <DataFrame/RandGen.h>

#include <chrono>
#include <iostream>

using namespace hmdf;

constexpr std::size_t ALIGNMENT = 256;
constexpr std::size_t ALIGNMENT = 64;
constexpr std::size_t SIZE = 100000000;

typedef StdDataFrame256<time_t> MyDataFrame;
typedef StdDataFrame64<time_t> MyDataFrame;

// -----------------------------------------------------------------------------

int main(int, char *[]) {
using namespace std::chrono;

std::cout << "Starting ... " << std::endl;
int main(int, char *[]) {

const auto first = time(nullptr);
auto index_vec =
MyDataFrame::gen_datetime_index("01/01/1970", "08/15/2019",
time_frequency::secondly, 1);
const auto index_sz = index_vec.size();
const auto first = high_resolution_clock::now();
MyDataFrame df;

df.load_data(
std::move(index_vec),
std::make_pair("normal", gen_normal_dist<double, ALIGNMENT>(index_sz)),
std::make_pair("log_normal", gen_lognormal_dist<double, ALIGNMENT>(index_sz)),
std::make_pair("exponential", gen_exponential_dist<double, ALIGNMENT>(index_sz)));
MyDataFrame::gen_sequence_index(0, SIZE, 1),
std::make_pair("normal", gen_normal_dist<double, ALIGNMENT>(SIZE)),
std::make_pair("log_normal", gen_lognormal_dist<double, ALIGNMENT>(SIZE)),
std::make_pair("exponential", gen_exponential_dist<double, ALIGNMENT>(SIZE)));

const auto second = time(nullptr);
const auto second = high_resolution_clock::now();

std::cout << "All data loadings are done. Calculating means ... "
<< second - first << std::endl;
<< double(duration_cast<microseconds>(second - first).count()) / 1000000.0
<< std::endl;

MeanVisitor<double, time_t> n_mv;
MeanVisitor<double, time_t> ln_mv;
MeanVisitor<double, time_t> e_mv;
VarVisitor<double, time_t> ln_vv;
CorrVisitor<double, time_t> e_ln_cv;

auto fut1 = df.visit_async<double>("normal", n_mv);
auto fut2 = df.visit_async<double>("log_normal", ln_mv);
auto fut3 = df.visit_async<double>("exponential", e_mv);
auto fut2 = df.visit_async<double>("log_normal", ln_vv);
auto fut3 = df.visit_async<double, double>("exponential", "log_normal", e_ln_cv);

std::cout << fut1.get().get_result() << ", "
<< fut2.get().get_result() << ", "
<< fut3.get().get_result() << std::endl;

const auto third = time(nullptr);
const auto third = high_resolution_clock::now();

std::cout << third - second << ", " << third - first
std::cout << double(duration_cast<microseconds>(third - second).count()) / 1000000.0
<< ", "
<< double(duration_cast<microseconds>(third - first).count()) / 1000000.0
<< " All done" << std::endl;
return (0);
}
Expand Down
35 changes: 35 additions & 0 deletions benchmarks/polars_performance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import datetime
import numpy as np
import polars as pl

# ------------------------------------------------------------------------------

SIZE: int = 100000000

first = datetime.datetime.now()
df = pl.DataFrame({"normal": np.random.normal(size=SIZE),
"log_normal": np.random.lognormal(size=SIZE),
"exponential": np.random.exponential(size=SIZE),
})
second = datetime.datetime.now()
print(f"All data loadings are done. Calculating means ... "
f"{(second - first).seconds}.{(second - first).microseconds}")

m1: float = df["normal"].mean()
m2: float = df["log_normal"].var()
m3: float = df.select(pl.corr("exponential", "log_normal"))

print(f"{m1}, {m2}, {m3}")
third = datetime.datetime.now()


print(f"{(third - second).seconds}.{(third - second).microseconds}, "
f"{(third - first).seconds}.{(third - first).microseconds} All done");

# ------------------------------------------------------------------------------

# Local Variables:
# mode:Python
# tab-width:4
# c-basic-offset:4
# End:

0 comments on commit d3f3122

Please sign in to comment.