@@ -0,0 +1,2013 @@
+#!/usr/bin/env python%0A%0Aimport locale%0Aimport random%0Aimport string%0Aimport sys%0Aimport time%0A%0Aimport mtbl%0A%0Areport_interval = 100000%0Amegabyte = 1048576.0%0A%0Adef merge_func(key, val0, val1):%0A    return val0 + val1%0A%0Adef main(fname, num_keys):%0A    sorter = mtbl.sorter(merge_func)%0A    writer = mtbl.writer(fname, compression=mtbl.COMPRESSION_SNAPPY)%0A%0A    a = time.time()%0A    last = a%0A    total_bytes = 0%0A    count = 0%0A    while count %3C num_keys:%0A        count += 1%0A        key = '%25020d' %25 random.randint(0, sys.maxint)%0A        val = random.choice(string.ascii_lowercase) * random.randint(1, 50)%0A        sorter%5Bkey%5D = val%0A        total_bytes += len(key) + len(val)%0A        if (count %25 report_interval) == 0:%0A            b = time.time()%0A            last_secs = b - last%0A            last = b%0A            sys.stderr.write('generated %25s entries (%25s MB) in %25s seconds, %25s entries/second%5Cn' %25 (%0A                locale.format('%25d', count, grouping=True),%0A                locale.format('%25d', total_bytes / megabyte, grouping=True),%0A                locale.format('%25f', last_secs, grouping=True),%0A                locale.format('%25d', report_interval / last_secs, grouping=True)%0A                )%0A            )%0A    sys.stderr.write('writing to output file %25s%5Cn' %25 fname)%0A    sorter.write(writer)%0A    b = time.time()%0A    total_secs = b - a%0A    sys.stderr.write('wrote %25s total entries (%25s MB) in %25s seconds, %25s entries/second%5Cn' %25 (%0A        locale.format('%25d', count, grouping=True),%0A        locale.format('%25d', total_bytes / megabyte, grouping=True),%0A        locale.format('%25f', total_secs, grouping=True),%0A        locale.format('%25d', count / total_secs, grouping=True)%0A        )%0A    )%0A%0Adef usage():%0A    sys.stderr.write('Usage: %25s %3CMTBL FILENAME%3E %3CNUMBER OF KEYS%3E%5Cn' %25 sys.argv%5B0%5D)%0A    sys.exit(1)%0A%0Aif __name__ == '__main__':%0A    locale.setlocale(locale.LC_ALL, '')%0A    if len(sys.argv) != 3:%0A        usage()%0A    try:%0A        fname = sys.argv%5B1%5D%0A        num_keys = int(sys.argv%5B2%5D)%0A    except:%0A        usage()%0A    main(fname, num_keys)%0A

add sorter example