Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

D: use ctRegex - #46

#46
Draft
kubo39 wants to merge 1 commit into
mariomka:optimizedmariomka/regex-benchmark:optimizedfrom
kubo39:d-compile-time-regexkubo39/regex-benchmark:d-compile-time-regexCopy head branch name to clipboard
Draft

D: use ctRegex#46
kubo39 wants to merge 1 commit into
mariomka:optimizedmariomka/regex-benchmark:optimizedfrom
kubo39:d-compile-time-regexkubo39/regex-benchmark:d-compile-time-regexCopy head branch name to clipboard

Conversation

@kubo39

@kubo39 kubo39 commented Apr 13, 2023

Copy link
Copy Markdown

No description provided.

@kubo39
kubo39 marked this pull request as draft April 13, 2023 10:21
@mariomka

Copy link
Copy Markdown
Owner

Thanks, my knowledge about D is limited, so I have some doubts.

  • What is the difference from the actual implementation? And why do you want to change it?
  • Does it make sense to keep only one implementation or both?

@kubo39

kubo39 commented Apr 14, 2023

Copy link
Copy Markdown
Author

Hi,

ctRegex compiles regular expression at compile-time.

I expected three things for performnace:

  1. avoid runtime regex construction cost, including for unicode.
  2. avoid heap allocations.
  3. compiles to native code and could be replaced with specialized instruction set.

see also this cool article, it's for rust's regex! macro (deprecated now described here, but very useful!).

However, in my local, the benchmark shows no difference. (sorry, I should check before send PR!)

I'm digging, and will close it found the reason.

@mariomka

Copy link
Copy Markdown
Owner

Thanks for the info!

I ran it on my computer, and there's a small change, not huge, but it's better.

@kubo39

kubo39 commented Apr 14, 2023

Copy link
Copy Markdown
Author

DMD - v2.103.0

  • slower than optimized branch.
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git branch
* d-compile-time-regex
  master
  optimized
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ dmd -O -release d/benchmark.d
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
307.404800 - 92
300.025700 - 5301
4.375800 - 5
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git checkout optimized
Switched to branch 'optimized'
Your branch is up to date with 'upstream/optimized'.
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ dmd -O -release d/benchmark.d
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
262.630300 - 92
269.145000 - 5301
5.823400 - 5
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
264.894800 - 92
268.622300 - 5301
5.635600 - 5
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git checkout d-compile-time-regex
Switched to branch 'd-compile-time-regex'
Your branch is up to date with 'origin/d-compile-time-regex'.
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ dmd -O -release d/benchmark.d
(dmd-2.103.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
290.224200 - 92
283.388900 - 5301
4.662600 - 5

LDC - v1.32.0

  • much faster than optimized.
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git checkout optimized
Switched to branch 'optimized'
Your branch is up to date with 'upstream/optimized'.
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ldc2 -O3 -release d/benchmark.d
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git branch
  d-compile-time-regex
  master
* optimized
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ldc2 -O3 -release d/benchmark.d
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
167.561100 - 92
163.916900 - 5301
4.397100 - 5
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ git checkout d-compile-time-regex
Switched to branch 'd-compile-time-regex'
Your branch is up to date with 'origin/d-compile-time-regex'.
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ldc2 -O3 -release d/benchmark.d
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
88.026900 - 92
88.755400 - 5301
3.594100 - 5
(ldc-1.32.0)kubo39@hinoda:~/dev/kubo39/regex-benchmark$ ./benchmark input-text.txt
88.634500 - 92
88.571300 - 5301
3.624200 - 5

@cyrusmsk

cyrusmsk commented May 31, 2023

Copy link
Copy Markdown

Just use:

import std.array;

auto m = data.matchAll(ctRegex!(pattern));
count = cast(int) m.array.length;

It is easy to read and run faster than foreach.

@cyrusmsk

Copy link
Copy Markdown

Thanks, my knowledge about D is limited, so I have some doubts.

  • What is the difference from the actual implementation? And why do you want to change it?
  • Does it make sense to keep only one implementation or both?

I propose to remain both. Currently ctRegex should work faster. But in D community many people don't like this approach - because it increase compilation time significantly. There were even some talks to remove ctRegex from std library. But it is just some rumors - and it is better to have both. It will be ease to remove one solution in future in case something will changed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.