Closed cyucelen closed 4 years ago
@cyucelen I was messing around more with the implementation of MatchDaysOfWeek.
I took my RegEx and turned it into a DFA. Here are the benchmarks for the string "monday tuesday wednesday thursday friday saturday sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday funday" for #3 and the DFA version.
DFA | #3 | |
---|---|---|
µs | 1.29 | 4.54 |
KB\op | 1856 | 4201 |
Allocs/op | 20 | 33 |
This method may be worth looking into. My code still needs to be optimized so there may still be performance gains to be had.
Can you share the DFA? I am really curious about it!
Sure. I will send it your way when I get to my desktop.
@cyucelen The DFA I implemented was this:
You can find the current code at https://github.com/dapryor/marker/tree/daysofweek_fsm Keep in mind this was a quickly thrown-together proof of concept haha. We could probably improve it more by making a more structured system or using maps.
Looks cool. I like to model state machines too but implementation of them in practice looks horrible most of the time. Since readability counts, let's keep the current implementation. Good job btw!
Create a matcher that matches days of week such as:
or with capital first character