iniparser: fprintf function is too slow when save something to file

In iniparser_dump_ini() and iniparser_dumpsection_ini(), the author uses fprintf to save ini data to file. When I use those functions ,I found it took me 7~8 seconds every time to save all info to a file. My embedded platform is MIPS and OS is Nuttx. After a long period of debugging, I used sprintf and fwrite to replace fprintf. Then it only took me 1 second to save completely. So I feel that I have the duty to report this .

在函数 iniparser_dump_ini() 和 iniparser_dumpsection_ini() 中,作者使用fprintf函数来保存数据到文件。当我用libiniparse库的时候,我发现每次将数据保存到文件都需要5~6秒。我的平台是MIPS,系统是Nuttx。经过一段时间的调试,我用sprintf来格式化数据,然后用fwrite将数据写入文件,这种方式只需要不到1秒钟的时间。我感觉我有责任来报告一下这个问题。

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@ndevilla @touilleMan I’d like to translate the FAQ to Chinese. It seems like that a lot of Chinese developer like libiniparser~ Could I make a pull request ?

@pacepi you should allow yourself a beer for the great work 😉

Thanks for the feedback @pacepi

@ndevilla do you thing this is worth mentioning in the faq ?

@touilleMan If we add setvbuf(f, NULL, _IOFBF, 0) before writing key-value to file, we can resolve this problem. SmartFrogFromChina is not the only person who met this problem~ I have checked glibc source code, setvbuf() function should be fully supported.