cyucelen / marker

🖍️ Marker is the easiest way to match and mark strings for colorful terminal outputs!
MIT License
47 stars 13 forks source link

Match days of week #11

Closed cyucelen closed 4 years ago

cyucelen commented 4 years ago

Create a matcher that matches days of week such as:

monday, tuesday...

or with capital first character

Monday, Tuesday..
dapryor commented 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.

cyucelen commented 4 years ago

Can you share the DFA? I am really curious about it!

dapryor commented 4 years ago

Sure. I will send it your way when I get to my desktop.

dapryor commented 4 years ago

@cyucelen The DFA I implemented was this: image

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.

cyucelen commented 4 years ago

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!