def main(use_pure = True, use_np = False): print( 'Doing 25 passes of each downsampling call') if use_pure: print('%-14s| %-14s| %-14s| %-14s| %-14s'%\ ('data length', 'result length', 'ulttb (sec)', 'python (sec)', 'speedup')) for dataset in DATA: for threshold in (32, 64, 128, 512, 1024, 4*1024): if threshold < len(dataset): res1 = res2 = None with Timer() as t1: for i in range(25): res1 = downsample(dataset, threshold) with Timer() as t2: for i in range(25): res2 = downsample_py(dataset, threshold) assert res1 == res2 print( '======================================='*3) print( '%-14i| %-14i| %-14f| %-14f| %-14f'%\ (len(dataset), threshold, t1.interval, t2.interval, (t2.interval/t1.interval))) if use_np: print('%-14s| %-14s| %-14s| %-14s| %-14s'%\ ('data length', 'result length', 'ulttb (sec)', 'python-np (sec)', 'speedup')) for dataset in DATA: for threshold in (32, 64, 512, 1024, 4*1024): if threshold < len(dataset): with Timer() as t1: for i in range(25): downsample(dataset, threshold) np_dataset = np.array(dataset) with Timer() as t2: for i in range(25): downsample_np(np_dataset, threshold) print( '======================================='*3) print( '%-14i| %-14i| %-14f| %-14f| %-14f'%\ (len(dataset), threshold, t1.interval, t2.interval, (t2.interval/t1.interval)))
def test_full(self): source = [] result = [] with open(os.path.join(pwd, 'source.csv')) as sf: for row in csv.reader(sf, delimiter=','): source.append([long(row[0]), float(row[1])]) with open(os.path.join(pwd,'downsampled.csv')) as sf: for row in csv.reader(sf, delimiter=','): result.append([long(row[0]), float(row[1])]) sampled = downsample(source, 500) self.assertEqual(len(result), len(sampled)) for s, r in zip(sampled, result): self.assertEqual(s[0], r[0]) self.assertEqual(s[1], r[1])
def test_wrong_args_bad_list_4(self): with self.assertRaises(ValueError): downsample([(1,2,), "test", "test", "test", "test", (5,6,7,8,9)], 3)
def test_wrong_args_bad_list_1(self): with self.assertRaises(ValueError): downsample([1,2,3,4,5,6,7,8,9], 3)
def test_wrong_args_int_int(self): with self.assertRaises(TypeError): downsample(3, 3)