Create account / Log in

Are regular expressions "=~" faster than multiple ==?

Topics related to the main Vassal engine.

Moderators: uckelman, Tim M

Are regular expressions "=~" faster than multiple ==?

Postby jrwatts » May 12th, 2021, 5:50 am

Just wondering if anyone has done any testing to determine whether a single regular expression match is faster than multiple equality matches combined with logical or?

In other words, is {GP =~ "(hand|research)"} faster or slower than {GP == "hand" || GP == "research"}? How about if I add a 3rd term?

I'm guessing I'll just have to do the testing myself, but I suspect the difference won't be easily noticeable. (I'm trying to find ways to speed up the end-of-generation processing in the Terraforming Mars module--I've already added a bunch of Fast Matches to the GKCs, without any appreciable difference, which was both surprising and disappointing).
Posts: 334
Joined: April 29th, 2020, 10:30 pm

Re: Are regular expressions "=~" faster than multiple ==?

Postby Cattlesquat » May 12th, 2021, 3:18 pm

Regex checks are almost certainly "ever so slightly slower" than ==, because of the overhead of the pattern matching code. You trade that for the convenience and "cleaner looking code". It seems unlikely you'd ever really notice the performance difference.

The amount of leverage you get with Fast Match depends on how much many pieces are being pre-culled from GKC processing, how many traits are on those pieces, and so forth -- so in other words it can vary widely. But the more "incisive" your Fast Matches are at culling the more performance you will get. I got some of my slow For the People commands to run in e.g. ~3 seconds instead of ~5 seconds -- which is certainly something although far from instantaneous. Ideally you have both a tight "location match" and a tight "property match". The tightest location matches of all are "Current Stack / Deck" and "Specific Deck", though obviously those aren't always suited to the task at hand.

User avatar
Posts: 1141
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest