Click here to Skip to main content
15,898,222 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 10:38
mvahoney the codewitch29-Jan-21 10:38 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
dandy7229-Jan-21 12:21
dandy7229-Jan-21 12:21 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 12:26
mvahoney the codewitch29-Jan-21 12:26 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
k505429-Jan-21 6:06
mvek505429-Jan-21 6:06 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 6:30
mvahoney the codewitch29-Jan-21 6:30 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
k505429-Jan-21 6:46
mvek505429-Jan-21 6:46 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 6:59
mvahoney the codewitch29-Jan-21 6:59 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
Stuart Dootson29-Jan-21 6:49
professionalStuart Dootson29-Jan-21 6:49 
You're not wrong...

Here's some code that scans through a 1GB string (finding a character at teh very end of it) with the four equivalent but different ways I could think of (std::string::find_first_of, std::string_view::find_first_of, std::find_first_of and strpbrk):
C++
 #include <algorithm>
 #include <chrono>
 #include <cstring>
 #include <iostream>
 #include <string>

int main()
{
   std::string s(size_t(1024) * 1024 * 1024, ' ');
   s.back() = 'c';

   auto start = std::chrono::steady_clock::now();
   auto x = s.find_first_of("abc");
   auto end = std::chrono::steady_clock::now();
   std::cout << "std::string::find_first_of -> " << x << " in "
             << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
             << " ms" << std::endl;

   start = std::chrono::steady_clock::now();
   std::string_view s_as_view{s.c_str(), s.size()};
   auto x1 = s_as_view.find_first_of("abc");
   end = std::chrono::steady_clock::now();
   std::cout << "std::string_view::find_first_of -> " << x1 << " in "
             << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
             << " ms" << std::endl;

   start = std::chrono::steady_clock::now();
   std::string needle{"abc"};
   auto x2 = std::distance(std::begin(s), std::find_first_of(std::begin(s), std::end(s), 
                           std::begin(needle), std::end(needle)));
      end = std::chrono::steady_clock::now();
   std::cout << "std::find_first_of -> " << x2 << " in "
             << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
             << " ms" << std::endl;

   start = std::chrono::steady_clock::now();
   auto y = std::distance(s.c_str(), strpbrk(s.c_str(), "abc"));
   end = std::chrono::steady_clock::now();
   std::cout << "strpbrk -> " << y << " in "
             << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
             << " ms" << std::endl;
}

and here's the output when compiled with cl.exe -std:c++17 -Ob2 -O2 -Os -EHsc a.cpp and run on the i7-6820HQ in my work laptop:
std::string::find_first_of -> 1073741823 in 552 ms
std::string_view::find_first_of -> 1073741823 in 557 ms
std::find_first_of -> 1073741823 in 2741 ms
strpbrk -> 1073741823 in 2359 ms

That's about 1.8GB/s for the first two, and around 423MB/s for strpbrk. However, when compiled with gcc-10 (with the command g++-10 -o ./a a.cpp -O3 -std=c++17) on Ubuntu 18.04 (same laptop - I'm using WSL), I get this:
std::string::find_first_of -> 1073741823 in 3341 ms
std::string_view::find_first_of -> 1073741823 in 3563 ms
std::find_first_of -> 1073741823 in 715 ms
strpbrk -> 1073741823 in 122 ms

That ranges from 300MB/s for the first two to about 8.2GB/s for strpbrk...

honey the codewitch wrote:
Does anyone know if GCC will work on Windows without some virtual env like MiniGW installed?


MinGW is actually OK - Cygwin is the 'gcc on Windows' that introduces nastiness. As this site says, "MinGW is a port of GCC to Windows. ... It produces standalone Windows executables which may be distributed in any manner." I'd use the distro from that site, or maybe one from this site
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
Sander Rossel29-Jan-21 9:24
professionalSander Rossel29-Jan-21 9:24 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 9:42
mvahoney the codewitch29-Jan-21 9:42 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
Sander Rossel29-Jan-21 11:19
professionalSander Rossel29-Jan-21 11:19 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 11:30
mvahoney the codewitch29-Jan-21 11:30 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
k505429-Jan-21 10:15
mvek505429-Jan-21 10:15 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
Sander Rossel29-Jan-21 11:19
professionalSander Rossel29-Jan-21 11:19 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
k505430-Jan-21 3:50
mvek505430-Jan-21 3:50 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
trønderen29-Jan-21 12:30
trønderen29-Jan-21 12:30 
GeneralRe: strpbrk() in Microsoft's VCLib is *slow* Pin
honey the codewitch29-Jan-21 13:38
mvahoney the codewitch29-Jan-21 13:38 
RantMicrosoft's Clownish Developer Prompt Pin
honey the codewitch29-Jan-21 1:17
mvahoney the codewitch29-Jan-21 1:17 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
OriginalGriff29-Jan-21 1:20
mveOriginalGriff29-Jan-21 1:20 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
honey the codewitch29-Jan-21 1:35
mvahoney the codewitch29-Jan-21 1:35 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
Randor 29-Jan-21 1:50
professional Randor 29-Jan-21 1:50 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
honey the codewitch29-Jan-21 2:18
mvahoney the codewitch29-Jan-21 2:18 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
Randor 29-Jan-21 2:27
professional Randor 29-Jan-21 2:27 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
honey the codewitch29-Jan-21 2:38
mvahoney the codewitch29-Jan-21 2:38 
GeneralRe: Microsoft's Clownish Developer Prompt Pin
Randor 29-Jan-21 2:51
professional Randor 29-Jan-21 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   401 votes