Show More
@@ -4,6 +4,7 | |||||
4 | from mercurial import cmdutil, scmutil, util, commands, obsolete |
|
4 | from mercurial import cmdutil, scmutil, util, commands, obsolete | |
5 | from mercurial import repoview, branchmap, merge, copies, error |
|
5 | from mercurial import repoview, branchmap, merge, copies, error | |
6 | import time, os, sys |
|
6 | import time, os, sys | |
|
7 | import random | |||
7 | import functools |
|
8 | import functools | |
8 |
|
9 | |||
9 | formatteropts = commands.formatteropts |
|
10 | formatteropts = commands.formatteropts | |
@@ -582,3 +583,80 def perfloadmarkers(ui, repo): | |||||
582 | timer, fm = gettimer(ui) |
|
583 | timer, fm = gettimer(ui) | |
583 | timer(lambda: len(obsolete.obsstore(repo.svfs))) |
|
584 | timer(lambda: len(obsolete.obsstore(repo.svfs))) | |
584 | fm.end() |
|
585 | fm.end() | |
|
586 | ||||
|
587 | @command('perflrucachedict', formatteropts + | |||
|
588 | [('', 'size', 4, 'size of cache'), | |||
|
589 | ('', 'gets', 10000, 'number of key lookups'), | |||
|
590 | ('', 'sets', 10000, 'number of key sets'), | |||
|
591 | ('', 'mixed', 10000, 'number of mixed mode operations'), | |||
|
592 | ('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')], | |||
|
593 | norepo=True) | |||
|
594 | def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000, | |||
|
595 | mixedgetfreq=50, **opts): | |||
|
596 | def doinit(): | |||
|
597 | for i in xrange(10000): | |||
|
598 | util.lrucachedict(size) | |||
|
599 | ||||
|
600 | values = [] | |||
|
601 | for i in xrange(size): | |||
|
602 | values.append(random.randint(0, sys.maxint)) | |||
|
603 | ||||
|
604 | # Get mode fills the cache and tests raw lookup performance with no | |||
|
605 | # eviction. | |||
|
606 | getseq = [] | |||
|
607 | for i in xrange(gets): | |||
|
608 | getseq.append(random.choice(values)) | |||
|
609 | ||||
|
610 | def dogets(): | |||
|
611 | d = util.lrucachedict(size) | |||
|
612 | for v in values: | |||
|
613 | d[v] = v | |||
|
614 | for key in getseq: | |||
|
615 | value = d[key] | |||
|
616 | value # silence pyflakes warning | |||
|
617 | ||||
|
618 | # Set mode tests insertion speed with cache eviction. | |||
|
619 | setseq = [] | |||
|
620 | for i in xrange(sets): | |||
|
621 | setseq.append(random.randint(0, sys.maxint)) | |||
|
622 | ||||
|
623 | def dosets(): | |||
|
624 | d = util.lrucachedict(size) | |||
|
625 | for v in setseq: | |||
|
626 | d[v] = v | |||
|
627 | ||||
|
628 | # Mixed mode randomly performs gets and sets with eviction. | |||
|
629 | mixedops = [] | |||
|
630 | for i in xrange(mixed): | |||
|
631 | r = random.randint(0, 100) | |||
|
632 | if r < mixedgetfreq: | |||
|
633 | op = 0 | |||
|
634 | else: | |||
|
635 | op = 1 | |||
|
636 | ||||
|
637 | mixedops.append((op, random.randint(0, size * 2))) | |||
|
638 | ||||
|
639 | def domixed(): | |||
|
640 | d = util.lrucachedict(size) | |||
|
641 | ||||
|
642 | for op, v in mixedops: | |||
|
643 | if op == 0: | |||
|
644 | try: | |||
|
645 | d[v] | |||
|
646 | except KeyError: | |||
|
647 | pass | |||
|
648 | else: | |||
|
649 | d[v] = v | |||
|
650 | ||||
|
651 | benches = [ | |||
|
652 | (doinit, 'init'), | |||
|
653 | (dogets, 'gets'), | |||
|
654 | (dosets, 'sets'), | |||
|
655 | (domixed, 'mixed') | |||
|
656 | ] | |||
|
657 | ||||
|
658 | for fn, title in benches: | |||
|
659 | timer, fm = gettimer(ui, opts) | |||
|
660 | timer(fn, title=title) | |||
|
661 | fm.end() | |||
|
662 |
@@ -75,6 +75,8 perfstatus | |||||
75 | benchmark the time to parse the on-disk markers for a repo |
|
75 | benchmark the time to parse the on-disk markers for a repo | |
76 | perflog (no help text available) |
|
76 | perflog (no help text available) | |
77 | perflookup (no help text available) |
|
77 | perflookup (no help text available) | |
|
78 | perflrucachedict | |||
|
79 | (no help text available) | |||
78 | perfmanifest (no help text available) |
|
80 | perfmanifest (no help text available) | |
79 | perfmergecalculate |
|
81 | perfmergecalculate | |
80 | (no help text available) |
|
82 | (no help text available) | |
@@ -139,6 +141,11 perfstatus | |||||
139 | $ hg perflog 2>&1 | filter_perf_output |
|
141 | $ hg perflog 2>&1 | filter_perf_output | |
140 | $ hg perflookup 2 2>&1 | filter_perf_output |
|
142 | $ hg perflookup 2 2>&1 | filter_perf_output | |
141 | ! result: 20 |
|
143 | ! result: 20 | |
|
144 | $ hg perflrucache 2>&1 | filter_perf_output | |||
|
145 | ! init | |||
|
146 | ! gets | |||
|
147 | ! sets | |||
|
148 | ! mixed | |||
142 |
$ |
|
149 | $ hg perfmanifest 2 2>&1 | filter_perf_output | |
143 | $ hg perfmergecalculate -r 3 2>&1 | filter_perf_output |
|
150 | $ hg perfmergecalculate -r 3 2>&1 | filter_perf_output | |
144 | $ hg perfmoonwalk 2>&1 | filter_perf_output |
|
151 | $ hg perfmoonwalk 2>&1 | filter_perf_output |
General Comments 0
You need to be logged in to leave comments.
Login now