相关疑难解决方法(0)

非常差的boost :: lexical_cast性能

Windows XP SP3.Core 2 Duo 2.0 GHz.我发现boost :: lexical_cast性能非常慢.想找出加速代码的方法.在visual c ++ 2008上使用/ O2优化并与java 1.6和python 2.6.2进行比较我看到以下结果.

整数铸造:

c++: 
std::string s ;
for(int i = 0; i < 10000000; ++i)
{
    s = boost::lexical_cast<string>(i);
}

java:
String s = new String();
for(int i = 0; i < 10000000; ++i)
{
    s = new Integer(i).toString();
}

python:
for i in xrange(1,10000000):
    s = str(i)
Run Code Online (Sandbox Code Playgroud)

我看到的时间是

c ++:6700毫秒

java:1178毫秒

python:6702毫秒

c ++和python一样慢,比java快6倍.

双铸:

c++:
std::string s ;
for(int i = 0; i < 10000000; …
Run Code Online (Sandbox Code Playgroud)

c++ boost lexical-cast

45
推荐指数
6
解决办法
3万
查看次数

标签 统计

boost ×1

c++ ×1

lexical-cast ×1