From bfc6af868be394b4f275d041d5e8345195c32fb2 Mon Sep 17 00:00:00 2001 From: Albert Ho Date: Thu, 1 Feb 2024 12:02:27 -0800 Subject: [PATCH] add init check --- .github/workflows/python-perf.yml | 5 ++++- binding/python/test_cobra_perf.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-perf.yml b/.github/workflows/python-perf.yml index 925778d7..beaecd51 100644 --- a/.github/workflows/python-perf.yml +++ b/.github/workflows/python-perf.yml @@ -41,10 +41,13 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] include: - os: ubuntu-latest + init_performance_threshold_sec: 0.001 performance_threshold_sec: 0.006 - os: windows-latest + init_performance_threshold_sec: 0.001 performance_threshold_sec: 0.006 - os: macos-latest + init_performance_threshold_sec: 0.001 performance_threshold_sec: 0.006 steps: @@ -62,7 +65,7 @@ jobs: run: pip install -r requirements.txt - name: Test - run: python test_cobra_perf.py ${{secrets.PV_VALID_ACCESS_KEY}} 100 ${{matrix.performance_threshold_sec}} + run: python test_cobra_perf.py ${{secrets.PV_VALID_ACCESS_KEY}} 100 ${{matrix.performance_threshold_sec}} ${{matrix.init_performance_threshold_sec}} perf-self-hosted: runs-on: ${{ matrix.machine }} diff --git a/binding/python/test_cobra_perf.py b/binding/python/test_cobra_perf.py index ceda40e9..9a9a14f6 100644 --- a/binding/python/test_cobra_perf.py +++ b/binding/python/test_cobra_perf.py @@ -22,8 +22,24 @@ class CobraPerformanceTestCase(unittest.TestCase): ACCESS_KEY = sys.argv[1] NUM_TEST_ITERATIONS = int(sys.argv[2]) PERFORMANCE_THRESHOLD_SEC = float(sys.argv[3]) + INIT_THRESHOLD_SEC = float(sys.argv.get(4, 0.005)) def test_performance(self): + init_results = [] + for i in range(self.NUM_TEST_ITERATIONS): + start = time() + c = Cobra(access_key=sys.argv[1], library_path=pv_library_path('../..')) + init_time = time.time() - start + + c.delete() + + if i > 0: + init_results.append(init_time) + + avg_init = sum(init_results) / self.NUM_TEST_ITERATIONS + print("Average init: %s" % avg_init) + self.assertLess(avg_init, self.INIT_THRESHOLD_SEC) + cobra = Cobra(access_key=sys.argv[1], library_path=pv_library_path('../..')) audio = read_wav_file( os.path.join(os.path.dirname(__file__), '../../res/audio/sample.wav'),