diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-01-02 14:16:10 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-01-02 14:16:10 +0000 |
commit | bb97f9e099c305128c5129bc396fb2983fc5fa90 (patch) | |
tree | 3f7d7e2c1615b19d5cf92ec618e8a98e4e5dbff1 | |
parent | ed86ea775f6711d091500c0f08fba2b282fdfc42 (diff) | |
download | genbackupdata-bb97f9e099c305128c5129bc396fb2983fc5fa90.tar.gz |
Add script to measure speed of data generation.
-rwxr-xr-x | generate-speed | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/generate-speed b/generate-speed new file mode 100755 index 0000000..472c8f2 --- /dev/null +++ b/generate-speed @@ -0,0 +1,70 @@ +#!/usr/bin/python +# Copyright 2010 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +import cProfile +import sys +import time + +import genbackupdatalib + + +def measure(repeats, func, arg, do_profile, profname): + def helper(): + for i in range(repeats): + func(arg) + + print 'measuring', profname + start_time = time.time() + start = time.clock() + if do_profile: + globaldict = globals().copy() + localdict = locals().copy() + cProfile.runctx('helper()', globaldict, localdict, + '%s.prof' % profname) + else: + helper() + end = time.clock() + end_time = time.time() + return end - start, end_time - start_time + + +def nop(size): + pass + + +def main(): + repeats = int(sys.argv[1]) + size1 = int(sys.argv[2]) + do_profile = sys.argv[3] == 'yes' + looptime = measure(repeats, nop, None, do_profile, 'calibrate') + + g = genbackupdatalib.DataGenerator(0) + result = measure(repeats, g.generate, size1, do_profile, 'generate') + + def speed(result, i): + total_data = repeats * size1 + return total_data / (result[i] - looptime[i]) + def humansize(size): + return '%4.1f MiB/s' % (size / 1024 / 1024) + def report(label, result): + cpu, wall = result + print '%-12s: %5.3f s (%8s)' % \ + (label, cpu, humansize(speed(result, 0))) + report('generate', result) + +if __name__ == '__main__': + main() |