<div dir="ltr"><div><div><div><div><div><div><div><div>Hi,<br><br></div>While translating (almost literally) Norvig's awesome regex golf from Python [1] to Racket [2], I'm facing a 25x slowdown (about 2s vs 50s). I've run the optimization coach and made the obvious changes (mainly adding `in-list` in `for` loops), tried to optimize `filter` and cache the regexps in a hash (to avoid their recompilation, since I need to keep the raw string too), but with no significant gain.<br>
<br></div>Reading the profile report, it seems that most of the time (99%) is spent in `regexp-match`, so I wanted to write a stripped down version showing that Python indeed is much faster than Racket on this particular function but this test case shows almost the contrary! (25s vs 23s)<br>
<br></div><div>So I'm stumped and I have no idea how to cut this 25x slowdown. Does anyone have an idea?<br><br></div>In [2], you can find:<br></div>- the regex golf file in Python (used for timing), which is almost identical to Norvig's<br>
</div>- the translation in Racket<br></div><div>- the stress test of `re.search` in Python<br></div>- the stress test of `regexp-match?` in Racket<br><br></div>Timings can be found at the bottom of each file.<br><br></div>
Note that the outputs of the programs are not exactly the same, because sets are used in Python and lists in Racket, but unless there are bugs in my code (which is not improbable) I don't think it matters a lot.<br><br>
<div>Thanks,<br></div><div>Laurent<br></div><div><div><div><div><div><div><div><div><br>[1] <a href="http://nbviewer.ipython.org/url/norvig.com/ipython/xkcd1313.ipynb">http://nbviewer.ipython.org/url/norvig.com/ipython/xkcd1313.ipynb</a><br>
[2] <a href="https://gist.github.com/Metaxal/777be153b50a35a2618c">https://gist.github.com/Metaxal/777be153b50a35a2618c</a><br><br></div></div></div></div></div></div></div></div></div>