Skip to content

Commit

Permalink
change timing test to test database upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Jan 21, 2021
1 parent a775ee1 commit d0e40ec
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions timing/ec2_timing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,34 @@
from riemann.search_strategy import SuperabundantSearchStrategy
from riemann.superabundant import partition_to_prime_factorization
from riemann.superabundant import partitions_of_n
from riemann.postgres_database import PostgresDivisorDb
from riemann.types import SearchState
from riemann.types import SuperabundantEnumerationIndex
import cProfile
import numba
import time

db = PostgresDivisorDb(data_source_name='')

# allow numba to compile
partition_to_prime_factorization(partitions_of_n(4)[0])
samples = 5
search_strategy = SuperabundantSearchStrategy().starting_from(
SuperabundantEnumerationIndex(71, 196047))
batch = search_strategy.next_batch(250000)


def run_test(search_state_start, batch_size):
search_strategy = SuperabundantSearchStrategy().starting_from(
search_state_start)

def run_test(batch):
times = []
for i in range(samples):
print(f'Running sample {i}')
start = time.time()
search_strategy.next_batch(batch_size)
db.upsert(batch)
end = time.time()
print(end - start)
times.append(end-start)
times.append(end - start)

return sum(times) / samples


print(run_test(SuperabundantEnumerationIndex(71, 196047), 250000))

print(run_test(batch))

print("------- cprofile -------")
cProfile.runctx(
'run_test(SuperabundantEnumerationIndex(71, 196047), 250000)', globals(), locals())
cProfile.runctx('run_test(batch)', globals(), locals())

0 comments on commit d0e40ec

Please sign in to comment.