def test_fast_slow_profiles_same(): start = datetime(2015, 11, 23) end = start + timedelta(days=1) slow_profiles = { host + '.ocf.berkeley.edu': UtilizationProfile.from_hostname(host, start, end) for host in list_desktops() } fast_profiles = UtilizationProfile.from_hostnames(list_desktops(), start, end) assert set(slow_profiles.keys()) == set(fast_profiles.keys()) for host in slow_profiles.keys(): slow = slow_profiles[host] fast = fast_profiles[host] assert slow.hostname == fast.hostname assert slow.start == fast.start assert slow.end == fast.end assert slow.sessions == fast.sessions
def test_fast_slow_profiles_same(): start = datetime(2015, 11, 23) end = start + timedelta(days=1) slow_profiles = { host + '.ocf.berkeley.edu': UtilizationProfile.from_hostname(host, start, end) for host in list_desktops() } fast_profiles = UtilizationProfile.from_hostnames(list_desktops(), start, end) assert set(slow_profiles.keys()) == set(fast_profiles.keys()) for host in slow_profiles.keys(): slow = slow_profiles[host] fast = fast_profiles[host] assert slow.hostname == fast.hostname assert slow.start == fast.start assert slow.end == fast.end assert slow.sessions == fast.sessions
from datetime import datetime from datetime import timedelta from ocflib.lab.stats import list_desktops from ocflib.lab.stats import UtilizationProfile @contextmanager def timeit(): start = time.time() yield print('Time taken: {}'.format(time.time() - start)) if __name__ == '__main__': start = datetime(2015, 11, 23) end = start + timedelta(days=1) print('Testing naive time to create profiles.') with timeit(): slow_profiles = { host + '.ocf.berkeley.edu': UtilizationProfile.from_hostname(host, start, end) for host in list_desktops() } print('Testing optimized time to create profiles.') with timeit(): fast_profiles = UtilizationProfile.from_hostnames( list_desktops(), start, end)
import time from contextlib import contextmanager from datetime import datetime from datetime import timedelta from ocflib.lab.stats import list_desktops from ocflib.lab.stats import UtilizationProfile @contextmanager def timeit(): start = time.time() yield print('Time taken: {}'.format(time.time() - start)) if __name__ == '__main__': start = datetime(2015, 11, 23) end = start + timedelta(days=1) print('Testing naive time to create profiles.') with timeit(): slow_profiles = { host + '.ocf.berkeley.edu': UtilizationProfile.from_hostname(host, start, end) for host in list_desktops() } print('Testing optimized time to create profiles.') with timeit(): fast_profiles = UtilizationProfile.from_hostnames(list_desktops(), start, end)