Bug 12069 – ctRegex is 3x slower then R-T ?

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2014-02-03T11:14:00Z
Last change time
2014-02-27T20:13:18Z
Keywords
pull
Assigned to
dmitry.olsh
Creator
dmitry.olsh

Comments

Comment #0 by dmitry.olsh — 2014-02-03T11:14:04Z
On behalf of Walter Bright, the benchmark: import std.datetime; import std.stdio; import std.regex; void ct() { string phone = "+31 650 903 7158"; //auto phoneReg = regex(r"^\+([1-9][0-9]*) [0-9 ]*$"); static phoneReg = ctRegex!r"^\+([1-9][0-9]*) [0-9 ]*$"; auto m = match(phone, phoneReg); assert(m); assert(m.captures[0] == "+31 650 903 7158"); assert(m.captures[1] == "31"); } void rt() { string phone = "+31 650 903 7158"; auto phoneReg = regex(r"^\+([1-9][0-9]*) [0-9 ]*$"); //static phoneReg = ctRegex!r"^\+([1-9][0-9]*) [0-9 ]*$"; auto m = match(phone, phoneReg); assert(m); assert(m.captures[0] == "+31 650 903 7158"); assert(m.captures[1] == "31"); } void main() { auto r = benchmark!(ct, rt)(1_000_000); writefln("ct = %s msecs, rt = %s", r[0].msecs, r[1].msecs); }
Comment #1 by dmitry.olsh — 2014-02-03T11:19:09Z
And a sample run: C:\cbx\mars>dmd foo -O -release -inline -noboundscheck C:\cbx\mars>foo ct = 6281 msecs, rt = 1984
Comment #2 by dmitry.olsh — 2014-02-03T11:51:46Z
Comment #3 by bugzilla — 2014-02-03T12:22:09Z
Should also add this benchmark code to: http://dlang.org/regular-expression.html
Comment #4 by github-bugzilla — 2014-02-03T13:50:01Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/b64c0919162a2bb9ac730f6f3980fe527c1bc9e0 fix issue 12069 On Win32 allocating large blocks (>512K) is forwarded to VirtualAlloc/VirtualFree. Doing these calls is expensive especially in a loop. As a temporary solution a block size of a segmented stack is decreased to ~1/8 of critical size. The code needs to be adapted once allocators are in std. https://github.com/D-Programming-Language/phobos/commit/908908164cbcf3fb6690912b155cd133c4861392 Merge pull request #1906 from blackwhale/issue-12069 Fix issue 12069
Comment #5 by github-bugzilla — 2014-02-03T15:20:12Z
Commit pushed to 2.065 at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/f1eadb913608ad1e1acd800e6c36b2b50b2a9f12 Merge pull request #1906 from blackwhale/issue-12069 Fix issue 12069
Comment #6 by dmitry.olsh — 2014-02-04T01:02:33Z
Closed, updating the article is worth a bug report on its own.
Comment #7 by github-bugzilla — 2014-02-27T20:13:18Z