defl/tests.old/test_popenTime.py

42 lines
762 B
Python
Raw Normal View History

2024-09-11 11:14:03 -04:00
#!/usr/bin/env python
from dataclasses import dataclass, field, KW_ONLY
import sys
import re
import os
import enum
from time import sleep
from operator import itemgetter
from defl import log, cl, Path
from defl import CLIError
from defl._typing_ import *
import defl
import time
import subprocess
def repeat(test, count=500):
times = []
for i in range(count):
start = time.time()
test()
times.append(time.time() - start)
avgTime = sum(times) / len(times)
return avgTime
def testPopen():
subprocess.Popen(['true']).communicate()
def testDeflPopen():
defl.RunCom(['true'])
res = repeat(testPopen)
print(f'testPopen={res*1000:.05f}ms')
res = repeat(testDeflPopen)
print(f'testDeflPopen={res*1000:.05f}ms')