def compare_load()

in cc_net/flat_hash_set.py [0:0]


def compare_load(*filenames):
    assert filenames, "No file given"

    def load_list():
        hashes = []
        for f in filenames:
            h = FlatHashSet()
            h.load(f)
            print(f"Loaded {h} from {f}.")
            hashes.append(h)
        return hashes

    def load_all(load, ext):
        hashes = FlatHashSet()
        for f in filenames:
            load(hashes, f + ext)

    def dump_all(hashes, dump, ext):
        for h, f in zip(hashes, filenames):
            dump(h, f + ext)

    hashes = load_list()
    dump_gp = getattr(FlatHashSet, "dump_gp")
    if dump_gp is not None:
        timeit("Dumping using gp.dump", dump_all, hashes, dump_gp, ".gp.test")
    timeit("Dumping using dump_np", dump_all, hashes, FlatHashSet.dump_np, ".npy.test")
    timeit(
        "Dumping using dump_np2", dump_all, hashes, FlatHashSet.dump_np2, ".npy2.test"
    )

    load_gp = getattr(FlatHashSet, "load_gp")
    if load_gp is not None:
        timeit("Loading using gp.load", load_all, load_gp, ".gp.test")
    timeit("Loading using load_np", load_all, FlatHashSet.load_np, ".npy.test")
    timeit("Loading using load_np2", load_all, FlatHashSet.load_np2, ".npy2.test")