alliedmodders / metamod-source

Metamod:Source - C++ Plugin Environment and Detour Library for the Source Engine
http://www.metamodsource.net/
Other
386 stars 88 forks source link

Replace fscanf with faster parsing #108

Closed PeakKS closed 1 year ago

PeakKS commented 1 year ago

fscanf is quite slow, this implementation is almost twice as fast. Tried fgets as well but getline was faster.

Elapsed CPU Time (FSCANF) = '7.91713' sec.
Elapsed CPU Time per Iteration (FSCANF, 500000) = '1.583425e-05' sec.
Elapsed CPU Time (FGETS) = '4.1562' sec.
Elapsed CPU Time per Iteration (FGETS, 500000) = '8.312396e-06' sec.
Elapsed CPU Time (GETLINE) = '4.13407' sec.
Elapsed CPU Time per Iteration (GETLINE, 500000) = '8.268138e-06' sec.

Might want to replace the parsing in ModuleInMemory as well

peace-maker commented 1 year ago

Did you experience performance problems with the current code and did those benchmarks using some SourceHook testing plugin or unit test? Complicating the code as a pre-mature optimization doesn't seem sustainable. It does sound probable that this code path might be slow with lots of quick hook/unhooks, but measurements would help.