-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from george0st/changes
Add core evaluation tests
- Loading branch information
Showing
7 changed files
with
222 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
class OutputPerformance: | ||
def __init__(self, row, col, process, thread, calls_sec): | ||
|
||
self.bundle_row = row | ||
self.bundle_col = col | ||
|
||
self.executor_process = process | ||
self.executor_thread = thread | ||
|
||
self.calls_sec = calls_sec | ||
|
||
def __str__(self): | ||
return f"bundle ({self.bundle_row}x{self.bundle_col}), executor ({self.executor_process}x{self.executor_thread}) = {self.calls_sec}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import os | ||
import unittest | ||
import logging | ||
from qgate_perf.parallel_executor import ParallelExecutor | ||
from qgate_perf.parallel_probe import ParallelProbe | ||
from qgate_perf.run_setup import RunSetup | ||
from qgate_perf.executor_helper import ExecutorHelper | ||
from qgate_perf.run_return import RunReturn | ||
from qgate_perf.bundle_helper import BundleHelper | ||
from qgate_perf.executor_helper import ExecutorHelper | ||
from qgate_perf.output_setup import OutputSetup | ||
import time | ||
from os import path | ||
import shutil | ||
|
||
def prf_calibration_onehundred_ms(run_setup: RunSetup) -> ParallelProbe: | ||
""" Function for performance testing""" | ||
|
||
# init (contain executor synchonization, 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 (True): | ||
|
||
# START - performance measure for specific part of code | ||
probe.start() | ||
|
||
for r in range(run_setup.bulk_row * run_setup.bulk_col): | ||
time.sleep(0.1) | ||
|
||
# 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): | ||
""" | ||
Test, if calculation of performance is correct | ||
IMPORTANT (main ideas) | ||
- all cases will have similar calls per second | ||
- the different duration time of tests does not change performance (calls per second) | ||
- peformance will affect size of bundle and amount of executors | ||
""" | ||
OUTPUT_ADR = "../output/test_perf/" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
shutil.rmtree(TestCaseCoreEvaluationCheck.OUTPUT_ADR, True) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
pass | ||
|
||
def test_expected_output1(self): | ||
|
||
generator = ParallelExecutor(prf_calibration_onehundred_ms, | ||
label = "GIL_impact", | ||
detail_output = True, | ||
output_file = path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt")) | ||
|
||
# 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 >= 9 and perf[0].calls_sec <= 11) | ||
|
||
# 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 >= 9 and perf[0].calls_sec <= 11) | ||
|
||
# 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 >= 9 and perf[0].calls_sec <= 11) | ||
|
||
def test_expected_output2(self): | ||
generator = ParallelExecutor(prf_calibration_onehundred_ms, | ||
label="GIL_impact", | ||
detail_output=True, | ||
output_file=path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt")) | ||
# 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 >= 19 and perf[0].calls_sec <= 21) | ||
|
||
# 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 >= 19 and perf[0].calls_sec <= 21) | ||
|
||
# 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 >= 19 and perf[0].calls_sec <= 21) | ||
|
||
def test_expected_output3(self): | ||
generator = ParallelExecutor(prf_calibration_onehundred_ms, | ||
label="GIL_impact", | ||
detail_output=True, | ||
output_file=path.join(self.OUTPUT_ADR, "perf_gil_impact_test.txt")) | ||
|
||
# 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 >= 39 and perf[0].calls_sec <= 41) | ||
|
||
# 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 >= 39 and perf[0].calls_sec <= 41) | ||
|
||
# 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 >= 39 and perf[0].calls_sec <= 41) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.