Skip to content

Conversation

isidroas
Copy link
Contributor

I confess that the optimization is minimal. But it is free because it does not complicates the code.

With this change, I measured the time spent on the first call of strlen():

$ python3 -c 'print(" "*4000 + "name=value")' > long_padding.ini
$ gcc examples/ini_dump.c ini.c -o examples/ini_dump
$ ltrace -T -e strlen ./examples/ini_dump long_padding.ini
ini_dump->strlen("name=value\n")                                     = 11 <0.000147>

and without this change (master):

ini_dump->strlen("                                "...)              = 4011 <0.001856>

The execution time was reduced from 1856 ns to 147 ns.

@benhoyt
Copy link
Owner

benhoyt commented Oct 20, 2024

This makes sense to me, thanks!

@benhoyt benhoyt merged commit cd5f939 into benhoyt:master Oct 20, 2024
2 checks passed
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.

2 participants