On Thu, Sep 26, 2019 at 02:16:04PM +0100, Daniel P. Berrangé wrote:
On Thu, Sep 26, 2019 at 12:39:39PM +0200, Erik Skultety wrote:
> On Tue, Sep 24, 2019 at 03:58:44PM +0100, Daniel P. Berrangé wrote:
> question 1) what's the benefit of compiling a regex and using it only once? Btw
> python does cache every pattern passed to re.match (and friends) so compilation
> IMO hardly ever makes sense unless you're doing 1000s of searches for the same
Some of the scripts here are run on the whole libvirt codebase so that
is the case here. For example just removing the pre-compilation of
regexes for comments from the spacing check script bumped the execution
time from 6.5s to 7.4s
Sadly, the one script where pre-compilation matters the most is the one
where separating them puts them far away from the usage to not fit on
one screen.
> pattern in which case the latency would naturally accumulate.
Ah, I've just seen the docs now
"The compiled versions of the most recent patterns passed to
re.compile() and the module-level matching functions are
cached, so programs that use only a few regular expressions
at a time needn’t worry about compiling regular expressions."
so with this in mind, I can probably just remove the 'compile' step from
all the scripts in this series. I haven't used it consistently to start
with.
For those regexes only executed on a fraction of lines this is
neligible, but it would be nice to keep them for those that run on every
line.
Jano
> question 2) why do we need the '''.* and
.*''' parts compared to the original
> perl regex? I'll go ahead and assume it's because re.match matches at the
> beginning of a string by default, in which case, shouldn't we use re.search
> which matches anywhere (that's what perl does by default) instead?
Yeah, I didn't notice the 're.search' function existed & had the
semantics
closer to Perl.
Regards,
Daniel
--
|:
https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|:
https://libvirt.org -o-
https://fstop138.berrange.com :|
|:
https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list