所有的东西都相等什么是最快的方式输出数据到磁盘在C + +? [英] All things equal what is the fastest way to output data to disk in C++?

查看:131
本文介绍了所有的东西都相等什么是最快的方式输出数据到磁盘在C + +?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的模拟代码很大程度上受CPU速度的约束。我不喜欢将数据输入/输出到用户界面,只需将其保存到磁盘作为计算。

I am running simulation code that is largely bound by CPU speed. I am not interested in pushing data in/out to a user interface, simply saving it to disk as it is computed.

什么是最快的解决方案,将减少开销? iostreams? printf?我以前读过,printf更快。这将取决于我的代码,是不可能得到一个没有profiling的答案?

What would be the fastest solution that would reduce overhead? iostreams? printf? I have previously read that printf is faster. Will this depend on my code and is it impossible to get an answer without profiling?

这将在Windows中运行,输出数据需要是文本格式,tab /逗号分隔,带有大多数浮点值的格式化/精度选项。

This will be running in Windows and the output data needs to be in text format, tab/comma separated, with formatting/precision options for mostly floating point values.

推荐答案

我的想法是你正在解决错误的问题。为什么要写出大量的文本格式的数据?如果是因为你想要它是人类可读的,写一个快速浏览器程序来读取二进制格式的数据在飞 - 这种方式模拟应用程序可以快速写出二进制数据,浏览器可以做格式化的工作数据和需要时。如果是因为你正在使用一些stats包来读取和分析文本数据,然后写入一个输入二进制数据。

My thought is that you are tackling the wrong problem. Why are you writing out vast quantities of text formatted data? If it is because you want it to be human readable, writing a quick browser program to read the data in binary format on the fly - this way the simulation application can quickly write out binary data and the browser can do the grunt work of formatting the data as and when needed. If it is because you are using some stats package to read and analyse text data then write one that inputs binary data.

这篇关于所有的东西都相等什么是最快的方式输出数据到磁盘在C + +?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆