[PATCH] commands: use a class as decorator to build table incrementally
Matt Mackall
mpm at selenic.com
Wed May 11 16:27:13 CDT 2011
On Wed, 2011-05-11 at 23:14 +0200, Adrian Buehlmann wrote:
> On 2011-05-11 20:23, Sune Foldager wrote:
> > On 2011-05-11 12:27, Matt Mackall wrote:
> >> On Wed, 2011-05-11 at 18:13 +0200, Adrian Buehlmann wrote:
> >>> # HG changeset patch
> >>> # User Adrian Buehlmann <adrian at cadifra.com>
> >>> # Date 1305097807 -7200
> >>> # Node ID 8b331aca1943f7840591dd3289e55f99ba164375
> >>> # Parent c97d8485b5fa46c94b8afcfab0cde97629ba4086
> >>> commands: use a class as decorator to build table incrementally
> >>>
> >>> this allows to define the table entries near the command function
> >>
> >> Thanks, we probably should have done something like this years ago.
> >
> > Did you(pl.) read the mail in the other thread about class'es here
> > performing substantially worse than functions? Not that I have the
> > slightest idea how much we are talking about.
>
> I've read that as well.
>
> I measured running from source with x64 python on Windows 7 x64.
>
> I did a 'hg log -l 1' on the mercurial repo.
>
> Using the Measure-Command from Windows PowerShell
>
> Measure-Command { hg log -l 1 }
>
> shows ~180 ms with or without my patch (after a couple of runs, so warm
> caches).
>
> Then I modified the patched commands.py like this:
>
> i = 0
> while i < 1000000:
> @command('version', [])
> def version_(ui):
> """output version and copyright information"""
> ui.write(_("Mercurial Distributed SCM (version %s)\n")
> % util.version())
> ui.status(_(
> "(see http://mercurial.selenic.com for more information)\n"
> "\nCopyright (C) 2005-2011 Matt Mackall and others\n"
> "This is free software; see the source for copying conditions. "
> "There is NO\nwarranty; "
> "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
> ))
> i += 1
>
> Which causes the decorator to be called one million time.
>
> The same hg log call was then ~1.9 seconds.
Not bad. If we assume 100 commands at 200us total, we're pretty much in
the noise for startup.
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list