Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Num parser performance #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

allykzam
Copy link

Saw "Optimized Numeric Type Handling" in the todo list in the readme, thought I'd poke around because it was Friday afternoon and I was bored. Adding this PR to give an overview of what I came up with; happy to put a proper PR together later if you want to use either of these implementations.

Minor points of note are marking isnumchar as inline, and replacing the isnegative function with a value; the current code appears to be running isnegative twice, even in an optimized release build.

Major differences in my code is the removal of the StringBuilder and calls to Double.TryParse and Int64.TryParse; I've replaced all that with tracking of the current value as a rational of p and q. After parsing, if no dot was found, p is returned as-is, if a dot was found, p and q are converted to double and divided appropriately. I'm sure there's probably some pros/cons to doing this for fractional values vs just using Double.TryParse.

Generated the timings provided on an i7 3770 in an iMac running Windows 7 inside parallels with 8 logical processors. Each timing was generated by resetting F# Interactive in VS to avoid GC from previous tests, then selecting and running lines 1-15 to get the parser pushed through the JIT, and then separately running the appropriate "speed test" code. YMMV 😬

@Rickasaurus
Copy link
Owner

Hi @amazingant , I'm sorry I totally missed this until now, thanks for putting some time in. I didn't realize anyone else was hacking on Barb.

By optimized numerics I meant the execution level as Barb only needs to be parsed once but is (at least as I use it) run many times (for each record). This is still interesting work though.

I'd like to see an optimization like this paired with FSCheck as it looks pretty complicated and I'd want to make sure no cases are left out.

I plan on putting much more effort into Barb over the coming months. Please let me know if you're still interested in hacking on it.

@allykzam
Copy link
Author

allykzam commented Feb 9, 2016

I had a wee bit of fun playing with it; I was working with my own parser at the time based on FParsec, and I really liked the concept of using active patterns as part of the parser logic. :)

I've built up a nice backlog of projects to work on since I worked on this, so I don't know as I'll be able to hack at it much for now. I'll try to check in as I have time, and I'll be sure to let you know if I start poking at something.

@hikarataas
Copy link

hikarataas commented Feb 21, 2024 via email

Repository owner deleted a comment from micici Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants