diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7ae2a7e4..0b77327a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: mv src/pocketpy.h src/pocketpy.cpp CL -std:c++17 -GR- -EHsc -O2 -LD -Fe:pocketpy src/pocketpy.cpp python3 scripts/run_tests.py - python3 scripts/run_tests.py benchmarks/ + python3 scripts/run_tests.py benchmark mkdir -p output/windows/x86_64 mv pocketpy.exe output/windows/x86_64 mv pocketpy.dll output/windows/x86_64 @@ -54,7 +54,7 @@ jobs: bash build_cpp.sh bash build_linux.sh python3 scripts/run_tests.py - python3 scripts/run_tests.py benchmarks/ + python3 scripts/run_tests.py benchmark mkdir -p output/linux/x86_64 mv pocketpy output/linux/x86_64 mv pocketpy.so output/linux/x86_64 diff --git a/benchmarks/primes.py b/benchmarks/primes.py index d74901d0..aa3c74c8 100644 --- a/benchmarks/primes.py +++ b/benchmarks/primes.py @@ -1,6 +1,3 @@ -import time -_0 = time.time() - UPPER_BOUND = 5000000 PREFIX = 32338 @@ -112,5 +109,3 @@ def verify(): verify() results = find(UPPER_BOUND, PREFIX) assert results == [323381, 323383, 3233803, 3233809, 3233851, 3233863, 3233873, 3233887, 3233897] - -print(round(time.time()-_0, 6), 's') diff --git a/benchmarks/simple.py b/benchmarks/simple.py index ef3f1865..f59c9136 100644 --- a/benchmarks/simple.py +++ b/benchmarks/simple.py @@ -1,6 +1,3 @@ -import time -_0 = time.time() - def is_prime(x): if x<2: return False @@ -20,5 +17,4 @@ def test(n): # dis(test) # dis(is_prime) -print(test(10000)) -print(round(time.time()-_0, 6), 's') \ No newline at end of file +print(test(10000)) \ No newline at end of file diff --git a/benchmarks/sort.py b/benchmarks/sort.py index 920f6b6a..fa12d733 100644 --- a/benchmarks/sort.py +++ b/benchmarks/sort.py @@ -1,9 +1,4 @@ -import time -_0 = time.time() - import random -a = [random.randint(-100000, 100000) for i in range(1500)] -a = sorted(a) - -print(round(time.time()-_0, 6), 's') \ No newline at end of file +a = [random.randint(-100000, 100000) for i in range(100000)] +a = sorted(a) \ No newline at end of file diff --git a/scripts/run_tests.py b/scripts/run_tests.py index 3aa29fe9..4010c676 100644 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -1,31 +1,38 @@ import os import sys +import time -def test_file(filepath): +def test_file(filepath, cpython=False): + if cpython: + return os.system("python3 " + filepath) == 0 if sys.platform == 'win32': return os.system("pocketpy.exe " + filepath) == 0 else: return os.system("./pocketpy " + filepath) == 0 def test_dir(path): - has_error = False + print("Testing directory:", path) for filename in os.listdir(path): if not filename.endswith('.py'): continue filepath = os.path.join(path, filename) print("> " + filepath) - code = test_file(filepath) - if not code: - has_error = True - exit(1) - return not has_error -if __name__ == '__main__': - if len(sys.argv) > 1: - d = sys.argv[1] - else: - d = 'tests/' - print("Testing directory:", d) - ok = test_dir(d) - if ok: - print("ALL TESTS PASSED") \ No newline at end of file + if path == 'benchmarks/': + _0 = time.time() + if not test_file(filepath, cpython=True): exit(1) + _1 = time.time() + if not test_file(filepath): exit(1) + _2 = time.time() + print(f' cpython: {_1 - _0:.6f}s (100%)') + print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)') + else: + if not test_file(filepath): exit(1) + +if len(sys.argv) == 2: + assert sys.argv[1] == 'benchmark' + d = 'benchmarks/' +else: + d = 'tests/' +test_dir(d) +print("ALL TESTS PASSED") \ No newline at end of file