Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added summary stat performance test #506

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions tests/regressions/python/sum_stat_perf_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright (c) 2018 Christopher Taylor
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

from phylanx import *
from phylanx.ast import *

import numpy as np
from time import time

def py_run(y, k):
x = np.zeros(k)
for i in range(k):
x[y[i]] += 1.0

@Phylanx
def phy_run(y, k):
x = constant(0.0, k)
for i in range(k):
x[y[i]] += 1.0

def py_run_mat(y, k):
x = np.zeros((k, k))
print(x.shape)
for i in range(k):
x[y[i], y[i]] += 1.0

@Phylanx
def phy_run_mat(y, k):
x = constant(0.0, make_list(k, k))
for i in range(k):
x[y[i], y[i]] += 1.0

def py_run_self_update(y, k):
x = np.zeros(k)
for i in range(k):
x[y[i]] = x[y[i]] + 1.0

@Phylanx
def phy_run_self_update(y, k):
x = constant(0.0, k)
for i in range(k):
x[y[i]] = x[y[i]] + 1.0

def py_run_mat_self_update(y, k):
x = np.zeros((k,k))
for i in range(k):
x[y[i], y[i]] = x[y[i], y[i]] + 1.0

@Phylanx
def phy_run_mat_self_update(y, k):
x = constant(0.0, make_list(k, k))
for i in range(k):
x[y[i], y[i]] = x[y[i], y[i]] + 1.0

if __name__ == "__main__":
K = 10000 # add a 0
y = np.random.randint(0, K, size=K)

func = [ py_run_mat \
, phy_run_mat \
, py_run \
, phy_run \
, py_run_self_update \
, phy_run_self_update \
, py_run_mat_self_update \
, phy_run_mat_self_update ]

func_nom = [ 'py_run_mat' \
, 'phy_run_mat' \
, 'py_run' \
, 'phy_run' \
, 'py_run_self_update' \
, 'phy_run_self_update' \
, 'py_run_mat_self_update'
, 'phy_run_mat_self_update' ]

for n, f in zip(func_nom, func):
print(n)
s = time()
f(y, K)
e = time()
print(e-s)