Created
August 12, 2017 00:32
-
-
Save bhavishyagopesh/ff0d9053bcd827aac4a594fec3d30ce4 to your computer and use it in GitHub Desktop.
To check the effect for int vs Long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import perf | |
from six.moves import xrange | |
def add_cmdline_args(cmd, args): | |
if args.benchmark: | |
cmd.append(args.benchmark) | |
CRUNCH_NO=10000000 | |
def bench_number_crunching(loops): | |
range_it = xrange(loops) | |
t0 = perf.perf_counter() | |
for _ in range_it: | |
x = 0 | |
while x < CRUNCH_NO: | |
x += 1 | |
dt = perf.perf_counter() - t0 | |
return dt | |
BENCHMARKS = { | |
"number_crunching": bench_number_crunching, | |
} | |
if __name__ == "__main__": | |
runner = perf.Runner(add_cmdline_args=add_cmdline_args) | |
runner.metadata['description'] = "Performance concurrency implemented using threading and multiprocessing" | |
parser = runner.argparser | |
parser.add_argument("benchmark", nargs='?', choices=sorted(BENCHMARKS)) | |
options = runner.parse_args() | |
if options.benchmark: | |
benchmarks = (options.benchmark,) | |
else: | |
benchmarks = sorted(BENCHMARKS) | |
for bench in benchmarks: | |
name = '%s' % bench | |
bench_func = BENCHMARKS[bench] | |
runner.bench_time_func(name, bench_func, inner_loops=10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment