Show More
@@ -488,6 +488,117 def perfbookmarks(ui, repo, **opts): | |||||
488 | timer(d) |
|
488 | timer(d) | |
489 | fm.end() |
|
489 | fm.end() | |
490 |
|
490 | |||
|
491 | @command('perfbundleread', formatteropts, 'BUNDLE') | |||
|
492 | def perfbundleread(ui, repo, bundlepath, **opts): | |||
|
493 | """Benchmark reading of bundle files. | |||
|
494 | ||||
|
495 | This command is meant to isolate the I/O part of bundle reading as | |||
|
496 | much as possible. | |||
|
497 | """ | |||
|
498 | from mercurial import ( | |||
|
499 | bundle2, | |||
|
500 | exchange, | |||
|
501 | streamclone, | |||
|
502 | ) | |||
|
503 | ||||
|
504 | def makebench(fn): | |||
|
505 | def run(): | |||
|
506 | with open(bundlepath, 'rb') as fh: | |||
|
507 | bundle = exchange.readbundle(ui, fh, bundlepath) | |||
|
508 | fn(bundle) | |||
|
509 | ||||
|
510 | return run | |||
|
511 | ||||
|
512 | def makereadnbytes(size): | |||
|
513 | def run(): | |||
|
514 | with open(bundlepath, 'rb') as fh: | |||
|
515 | bundle = exchange.readbundle(ui, fh, bundlepath) | |||
|
516 | while bundle.read(size): | |||
|
517 | pass | |||
|
518 | ||||
|
519 | return run | |||
|
520 | ||||
|
521 | def makestdioread(size): | |||
|
522 | def run(): | |||
|
523 | with open(bundlepath, 'rb') as fh: | |||
|
524 | while fh.read(size): | |||
|
525 | pass | |||
|
526 | ||||
|
527 | return run | |||
|
528 | ||||
|
529 | # bundle1 | |||
|
530 | ||||
|
531 | def deltaiter(bundle): | |||
|
532 | for delta in bundle.deltaiter(): | |||
|
533 | pass | |||
|
534 | ||||
|
535 | def iterchunks(bundle): | |||
|
536 | for chunk in bundle.getchunks(): | |||
|
537 | pass | |||
|
538 | ||||
|
539 | # bundle2 | |||
|
540 | ||||
|
541 | def forwardchunks(bundle): | |||
|
542 | for chunk in bundle._forwardchunks(): | |||
|
543 | pass | |||
|
544 | ||||
|
545 | def iterparts(bundle): | |||
|
546 | for part in bundle.iterparts(): | |||
|
547 | pass | |||
|
548 | ||||
|
549 | def seek(bundle): | |||
|
550 | for part in bundle.iterparts(): | |||
|
551 | part.seek(0, os.SEEK_END) | |||
|
552 | ||||
|
553 | def makepartreadnbytes(size): | |||
|
554 | def run(): | |||
|
555 | with open(bundlepath, 'rb') as fh: | |||
|
556 | bundle = exchange.readbundle(ui, fh, bundlepath) | |||
|
557 | for part in bundle.iterparts(): | |||
|
558 | while part.read(size): | |||
|
559 | pass | |||
|
560 | ||||
|
561 | return run | |||
|
562 | ||||
|
563 | benches = [ | |||
|
564 | (makestdioread(8192), 'read(8k)'), | |||
|
565 | (makestdioread(16384), 'read(16k)'), | |||
|
566 | (makestdioread(32768), 'read(32k)'), | |||
|
567 | (makestdioread(131072), 'read(128k)'), | |||
|
568 | ] | |||
|
569 | ||||
|
570 | with open(bundlepath, 'rb') as fh: | |||
|
571 | bundle = exchange.readbundle(ui, fh, bundlepath) | |||
|
572 | ||||
|
573 | if isinstance(bundle, changegroup.cg1unpacker): | |||
|
574 | benches.extend([ | |||
|
575 | (makebench(deltaiter), 'cg1 deltaiter()'), | |||
|
576 | (makebench(iterchunks), 'cg1 getchunks()'), | |||
|
577 | (makereadnbytes(8192), 'cg1 read(8k)'), | |||
|
578 | (makereadnbytes(16384), 'cg1 read(16k)'), | |||
|
579 | (makereadnbytes(32768), 'cg1 read(32k)'), | |||
|
580 | (makereadnbytes(131072), 'cg1 read(128k)'), | |||
|
581 | ]) | |||
|
582 | elif isinstance(bundle, bundle2.unbundle20): | |||
|
583 | benches.extend([ | |||
|
584 | (makebench(forwardchunks), 'bundle2 forwardchunks()'), | |||
|
585 | (makebench(iterparts), 'bundle2 iterparts()'), | |||
|
586 | (makebench(seek), 'bundle2 part seek()'), | |||
|
587 | (makepartreadnbytes(8192), 'bundle2 part read(8k)'), | |||
|
588 | (makepartreadnbytes(16384), 'bundle2 part read(16k)'), | |||
|
589 | (makepartreadnbytes(32768), 'bundle2 part read(32k)'), | |||
|
590 | (makepartreadnbytes(131072), 'bundle2 part read(128k)'), | |||
|
591 | ]) | |||
|
592 | elif isinstance(bundle, streamclone.streamcloneapplier): | |||
|
593 | raise error.Abort('stream clone bundles not supported') | |||
|
594 | else: | |||
|
595 | raise error.Abort('unhandled bundle type: %s' % type(bundle)) | |||
|
596 | ||||
|
597 | for fn, title in benches: | |||
|
598 | timer, fm = gettimer(ui, opts) | |||
|
599 | timer(fn, title=title) | |||
|
600 | fm.end() | |||
|
601 | ||||
491 | @command('perfchangegroupchangelog', formatteropts + |
|
602 | @command('perfchangegroupchangelog', formatteropts + | |
492 | [('', 'version', '02', 'changegroup version'), |
|
603 | [('', 'version', '02', 'changegroup version'), | |
493 | ('r', 'rev', '', 'revisions to add to changegroup')]) |
|
604 | ('r', 'rev', '', 'revisions to add to changegroup')]) |
@@ -55,6 +55,8 perfstatus | |||||
55 | benchmark parsing bookmarks from disk to memory |
|
55 | benchmark parsing bookmarks from disk to memory | |
56 | perfbranchmap |
|
56 | perfbranchmap | |
57 | benchmark the update of a branchmap |
|
57 | benchmark the update of a branchmap | |
|
58 | perfbundleread | |||
|
59 | Benchmark reading of bundle files. | |||
58 | perfcca (no help text available) |
|
60 | perfcca (no help text available) | |
59 | perfchangegroupchangelog |
|
61 | perfchangegroupchangelog | |
60 | Benchmark producing a changelog group for a changegroup. |
|
62 | Benchmark producing a changelog group for a changegroup. | |
@@ -173,3 +175,7 Check perf.py for historical portability | |||||
173 | $ (testrepohg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py; |
|
175 | $ (testrepohg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py; | |
174 | > testrepohg files -r tip glob:mercurial/*.c glob:mercurial/*.py) | |
|
176 | > testrepohg files -r tip glob:mercurial/*.c glob:mercurial/*.py) | | |
175 | > "$TESTDIR"/check-perf-code.py contrib/perf.py |
|
177 | > "$TESTDIR"/check-perf-code.py contrib/perf.py | |
|
178 | contrib/perf.py:498: | |||
|
179 | > from mercurial import ( | |||
|
180 | import newer module separately in try clause for early Mercurial | |||
|
181 | [1] |
General Comments 0
You need to be logged in to leave comments.
Login now