def _run_test(fn, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False t = fn(es) start = time.time() if isinstance(t, dict): for _ in range(num_its): in_ = 0 for e in sorted(t): in_ += 1 else: for _ in range(num_its): in_ = 0 for e in t: in_ += 1 end = time.time() diff = (end - start) / num_its if in_ != len(t): raise RuntimeError(not_in) # if len(t) != len(set(es)): # raise RunteimError(len(t)) return diff
def _run_test(fn, type_, num_items, num_its): diff = 0 for _ in range(num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False t = fn(es) e = es[0] start = time.time() if isinstance(t, bintrees.FastRBTree): del t[e: e + 10] elif isinstance(t, banyan.SortedSet): t.remove(e, e + 10) elif isinstance(t, set): t = set([i for i in t if i < e or e + 10 >= i]) else: fff end = time.time() diff += (end - start) / num_its # if len(t) != len(set(es)): # raise RunteimError(len(t)) return diff
def _run_test(fn, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False start = time.time() for _ in range(num_its): t = fn() if isinstance(t, dict): for i, e in enumerate(es): t[e] = 1 if i % 1 == 0: for ee in sorted(t): pass else: for i, e in enumerate(es): t[e] = 1 if i % 1 == 0: for ee in t: pass end = time.time() diff = (end - start) / num_its return diff
def _run_test(fn, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False t = fn(es) start = time.time() if isinstance(t, set): for _ in range(num_its): in_ = 0 for e in sorted(t): in_ += 1 else: for _ in range(num_its): in_ = 0 for e in t: in_ += 1 end = time.time() diff = (end - start) / num_its if in_ != len(t): raise RuntimeError(not_in) # if len(t) != len(set(es)): # raise RunteimError(len(t)) return diff
def _run_test(fn, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False start = time.time() for _ in range(num_its): fn(es) end = time.time() diff = (end - start) / num_its return diff
def _run_test(fn, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False t = fn(es) start = time.time() sum_ = 1 for _ in range(num_its): for e in es: sum_ += t[e] end = time.time() diff = (end - start) / num_its if sum_ == 0: raise RuntimeError(not_in) return diff
def _run_test(fn_types, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False e = es[0] t = fn_types[0](es) start = time.time() for _ in range(num_its): end = time.time() if fn_types[1] is None: t[e: e + 10] = [v + 1 for v in t[e: e + 10]] else: t = fn_types[1]([(k, v + 1) if e <= k < e + 10 else (k, v) for (k, v) in t.items()]) end = time.time() return (end - start) / num_its
def _run_test(fn_types, type_, num_items, num_its): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False e = es[0] t = fn_types[0](es) start = time.time() for _ in range(num_its): end = time.time() if fn_types[1] is None: t[e:e + 10] = [v + 1 for v in t[e:e + 10]] else: t = fn_types[1]([(k, v + 1) if e <= k < e + 10 else (k, v) for (k, v) in t.items()]) end = time.time() return (end - start) / num_its
def _run_test(fn, type_, num_items, num_its, mini_num_items): if type_ == int: es = _src.random_ints(num_items) elif type_ == str: es = _src.random_strings(num_items, 8) else: assert False t = fn(es) start = time.time() for i in range(max(num_items - mini_num_items - 1, 0)): for e in es[i: i + mini_num_items]: not_in = 0 for _ in range(num_its): if e not in t: not_in += 1 if not_in != 0: raise RuntimeError(not_in) end = time.time() diff = (end - start) / num_its return diff