Skip to content

Commit

Permalink
BENCH: NPV: Benchmark naive for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai-Striega committed Dec 3, 2023
1 parent 8fbc349 commit a1f0743
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy_financial as npf


class Npv2DCashflows:
class Npv2D:

param_names = ["n_cashflows", "cashflow_lengths", "rates_lengths"]
params = [
Expand All @@ -30,5 +30,17 @@ def setup(self, n_cashflows, cashflow_lengths, rates_lengths):
def time_broadcast(self, n_cashflows, cashflow_lengths, rates_lengths):
npf.npv(self.rates, self.cashflows)

def time_for_loop(self, n_cashflows, cashflow_lengths, rates_lengths):
for i, rate in enumerate(self.rates):
for j, cashflow in enumerate(self.cashflows):
npf.npv(rate, cashflow)

def time_broadcast_decimal(self, n_cashflows, cashflow_lengths, rates_lengths):
npf.npv(self.rates_decimal, self.cashflows_decimal)

def time_for_loop_decimal(self, n_cashflows, cashflow_lengths, rates_lengths):
for i, rate in enumerate(self.rates_decimal):
for j, cashflow in enumerate(self.cashflows_decimal):
npf.npv(rate, cashflow)


0 comments on commit a1f0743

Please sign in to comment.