Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

https://github.com/rurban/cmph/commit/4bb99882cc21fd44e86602...

I did not nothing wrong :)

And I remember better now. I changed stack access to immediate global access to const arrays. And insane was the compilation time, not so much the runtime. -O2 timed out, and if it compiled it was 10x slower run-time. Now compilation is immediate.

This compiles large perfect hashes to C code. Like gperf, just better and for huge arrays.



Thank you for linking.

In this case, as I understand, you switched from a local array which is re-initialized with values upon each function invocation to a global array that is pre-initialized before even the program starts. So my understanding is you're measuring the speed between repeated re-initialization of your local array and no initialization at all — not between "relative" stack access and "absolute" heap or global memory access.

As I understand, to do it the way you wanted initially, your local array must be `static const` instead of just const (so that there's a single copy of it, essentially making it a global variable as well). To be honest, I am not sure why C compiler doesn't optimize it this way automatically, likely I don't know C spec well enough to know the reasons.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: