You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Travis Vitek (JIRA)" <ji...@apache.org> on 2008/02/05 20:43:07 UTC
[jira] Commented: (STDCXX-249) std::operator>>(istream, string&)
inefficient
[ https://issues.apache.org/jira/browse/STDCXX-249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565855#action_12565855 ]
Travis Vitek commented on STDCXX-249:
-------------------------------------
Performance test follows...
{noformat}
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
int main (int argc, char* argv[])
{
size_t loops = 1000;
if (1 < argc)
loops = strtoul (argv [1], 0, 0);
const char* file = __FILE__;
if (2 < argc)
file = argv [2];
std::ifstream ifs (file);
if (!ifs.is_open ())
return 1;
size_t tokens = 0;
std::string token;
token.reserve (100);
for (size_t i = 0; i < loops; ++i)
{
while (ifs >> token)
++tokens;
ifs.clear ();
ifs.seekg (0);
}
std::cout << tokens << std::endl;
return 0;
}
{noformat}
Results on Linux/GCC 12D build before and after...
{noformat}
$ time ./t 10000 /nfs/devco/vitek/stdcxx/trunk/tests/strings/21.string.io.cpp
77630000
real 0m7.269s
user 0m6.722s
sys 0m0.466s
$ time ./t 10000 /nfs/devco/vitek/stdcxx/trunk/tests/strings/21.string.io.cpp
77630000
real 0m7.148s
user 0m6.667s
sys 0m0.142s
{noformat}
So I'm seeing almost no difference in terms of performance with a release build on Linux. There is a difference for an 11s build...
{noformat}
$ time ./t 1000 /nfs/devco/vitek/stdcxx/trunk/tests/strings/21.string.io.cpp
7763000
real 0m6.753s
user 0m6.521s
sys 0m0.210s
$ time ./t 1000 /nfs/devco/vitek/stdcxx/trunk/tests/strings/21.string.io.cpp
7763000
real 0m3.781s
user 0m3.755s
sys 0m0.017s
{noformat}
> std::operator>>(istream, string&) inefficient
> ---------------------------------------------
>
> Key: STDCXX-249
> URL: https://issues.apache.org/jira/browse/STDCXX-249
> Project: C++ Standard Library
> Issue Type: Improvement
> Components: 21. Strings
> Affects Versions: 4.1.2, 4.1.3, 4.1.4, 4.2.0
> Environment: all
> Reporter: Martin Sebor
> Assignee: Travis Vitek
> Priority: Minor
> Fix For: 4.2.1
>
> Original Estimate: 8h
> Remaining Estimate: 8h
>
> The string extractor reads and appends one character at a time. It could be made more efficient by extracting and appending all non-whitespace characters that are available in the buffer in chunks. See the definition of the operator here:
> http://svn.apache.org/viewvc/stdcxx/trunk/include/istream.cc?revision=383265
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.