Skip to content

Commit

Permalink
Merge pull request #51 from george0st/changes
Browse files Browse the repository at this point in the history
Increase time precision
  • Loading branch information
george0st authored Oct 4, 2024
2 parents 7266436 + e87ddd7 commit 1726ceb
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 17 deletions.
11 changes: 5 additions & 6 deletions qgate_perf/parallel_probe.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#import datetime
#import time
import os
import json
from time import time, sleep
from time import time, sleep, perf_counter
from datetime import datetime
from qgate_perf.standard_deviation import StandardDeviation
from qgate_perf.file_format import FileFormat
Expand Down Expand Up @@ -47,19 +45,20 @@ def __init__(self, run_setup: RunSetup, exception=None):

def start(self):
""" Start measurement each test"""
self.start_time_one_shot = time()
self.start_time_one_shot = perf_counter()

def stop(self) -> bool:
"""Test, if it is possible to stop execution, based on duration of test
:return: True - stop execution, False - continue in execution
"""
stop_time_one_shot = time()
stop_time_one_shot = perf_counter()

duration_one_shot = stop_time_one_shot - self.start_time_one_shot
self._core_calc(duration_one_shot)

# Is it possible to end performance testing?
if (stop_time_one_shot - self.init_time) >= self.duration_second:
if (time() - self.init_time) >= self.duration_second:
self._core_close()
return True
return False
Expand Down
153 changes: 142 additions & 11 deletions tests/test_core_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import time
import unittest
from qgate_perf.parallel_executor import ParallelExecutor
from qgate_perf.parallel_probe import ParallelProbe
from qgate_perf.run_setup import RunSetup
from qgate_perf.output_setup import OutputSetup
from time import sleep
import shutil

def prf_calibration_onehundred_ms(run_setup: RunSetup) -> ParallelProbe:
def prf_calibration_100_ms(run_setup: RunSetup) -> ParallelProbe:
""" Function for performance testing"""

# init (contain executor synchronization, if needed)
Expand All @@ -31,7 +33,7 @@ def prf_calibration_onehundred_ms(run_setup: RunSetup) -> ParallelProbe:
# return outputs
return probe

def prf_calibration_ten_ms(run_setup: RunSetup) -> ParallelProbe:
def prf_calibration_10_ms(run_setup: RunSetup) -> ParallelProbe:
""" Function for performance testing"""

# init (contain executor synchronization, if needed)
Expand All @@ -57,6 +59,31 @@ def prf_calibration_ten_ms(run_setup: RunSetup) -> ParallelProbe:
# return outputs
return probe

def prf_calibration_4_ms(run_setup: RunSetup) -> ParallelProbe:
""" Function for performance testing"""

# init (contain executor synchronization, if needed)
probe = ParallelProbe(run_setup)

if run_setup.is_init:
print(f"!!! INIT CALL !!! {run_setup.bulk_row} x {run_setup.bulk_col}")

while 1:

# START - performance measure for specific part of code
probe.start()

sleep(0.004)

# STOP - performance measure specific part of code
if probe.stop():
break

if run_setup.param("generate_error"):
raise Exception('Simulated error')

# return outputs
return probe

class TestCaseCoreEvaluation(unittest.TestCase):
"""
Expand All @@ -71,6 +98,7 @@ class TestCaseCoreEvaluation(unittest.TestCase):

@classmethod
def setUpClass(cls):
OutputSetup().human_precision=7
shutil.rmtree(TestCaseCoreEvaluation.OUTPUT_ADR, True)

@classmethod
Expand All @@ -79,7 +107,7 @@ def tearDownClass(cls):

def test_expected_output100ms_1(self):

generator = ParallelExecutor(prf_calibration_onehundred_ms,
generator = ParallelExecutor(prf_calibration_100_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)
Expand Down Expand Up @@ -112,7 +140,7 @@ def test_expected_output100ms_1(self):
self.assertTrue(perf[0].calls_sec >= 9 and perf[0].calls_sec <= 10)

def test_expected_output100ms_2(self):
generator = ParallelExecutor(prf_calibration_onehundred_ms,
generator = ParallelExecutor(prf_calibration_100_ms,
label="GIL_impact",
detail_output=True,
output_file = None)
Expand Down Expand Up @@ -144,7 +172,7 @@ def test_expected_output100ms_2(self):
self.assertTrue(perf[0].calls_sec >= 19 and perf[0].calls_sec <= 20)

def test_expected_output100ms_3(self):
generator = ParallelExecutor(prf_calibration_onehundred_ms,
generator = ParallelExecutor(prf_calibration_100_ms,
label="GIL_impact",
detail_output=True,
output_file = None)
Expand Down Expand Up @@ -176,9 +204,9 @@ def test_expected_output100ms_3(self):
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 39 and perf[0].calls_sec <= 40)

def test_expected_output10ms_1(self):
def test_expected_output010ms_1(self):

generator = ParallelExecutor(prf_calibration_ten_ms,
generator = ParallelExecutor(prf_calibration_10_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)
Expand Down Expand Up @@ -210,9 +238,9 @@ def test_expected_output10ms_1(self):
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 90 and perf[0].calls_sec <= 100)

def test_expected_output10ms_2(self):
def test_expected_output010ms_2(self):

generator = ParallelExecutor(prf_calibration_ten_ms,
generator = ParallelExecutor(prf_calibration_10_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)
Expand Down Expand Up @@ -244,9 +272,9 @@ def test_expected_output10ms_2(self):
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 180 and perf[0].calls_sec <= 200)

def test_expected_output10ms_3(self):
def test_expected_output010ms_3(self):

generator = ParallelExecutor(prf_calibration_ten_ms,
generator = ParallelExecutor(prf_calibration_10_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)
Expand Down Expand Up @@ -277,3 +305,106 @@ def test_expected_output10ms_3(self):
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 360 and perf[0].calls_sec <= 400)

def test_expected_output004ms_1(self):

generator = ParallelExecutor(prf_calibration_4_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)

# first
setup=RunSetup(duration_second = 1, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[1,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 200 and perf[0].calls_sec <= 250)

# second
setup=RunSetup(duration_second = 2, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[1,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 200 and perf[0].calls_sec <= 250)

# third
setup=RunSetup(duration_second = 10, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[1,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 200 and perf[0].calls_sec <= 250)

def test_expected_output004ms_2(self):

generator = ParallelExecutor(prf_calibration_4_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)

# first
setup=RunSetup(duration_second = 1, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[2,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 400 and perf[0].calls_sec <= 500)

# second
setup=RunSetup(duration_second = 2, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[2,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 400 and perf[0].calls_sec <= 500)

# third
setup=RunSetup(duration_second = 10, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[2,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 400 and perf[0].calls_sec <= 500)

def test_expected_output004ms_3(self):

generator = ParallelExecutor(prf_calibration_4_ms,
label = "GIL_impact",
detail_output = True,
output_file = None)

# first
setup=RunSetup(duration_second = 1, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[4,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 800 and perf[0].calls_sec <= 1000)

# second
setup=RunSetup(duration_second = 2, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[4,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 800 and perf[0].calls_sec <= 1000)

# third
setup=RunSetup(duration_second = 10, start_delay = 0)
state, perf = generator.run_bulk_executor(bulk_list = [[1,1]],
executor_list = [[4,1]],
run_setup = setup,
return_performance = True)
self.assertTrue(state)
self.assertTrue(perf[0].calls_sec >= 800 and perf[0].calls_sec <= 1000)

0 comments on commit 1726ceb

Please sign in to comment.