C++ 10 Feb 2011 18:24:56

C++ String Compare Performance

A performance comparison of the speed of various ways to compare strings in C++. In this test, all comparisons are of not-equal strings.

Idea from #C++ on QuakeNet, where we always advocate using std::string over various char* functions. I wondered what, if any, the penalty for doing so was.

Sources

Things Tested

  • a hand-written naive comparator loop; used as baseline
  • string == string
  • string == const char*
  • strcmp(const char*, const char*) == 0
  • strcmp(const char*, string.c_str()) == 0
  • strcmp(string.c_str(), string.c_str()) == 0
  • string.compare(string)
  • string.compare(const char*)
  • …and then the whole thing with different offsets.


Continue Reading »

C++ 28 Jan 2011 16:21:01

C++ Read Whole File Performance

A performance comparison of the speed of various ways to read an entire file into an std::string in C++.

Idea from BD-Calvin in #C++ on QuakeNet.

Sources

Things Tested

  • writing to a stringstream, then pulling data out as string
  • constructing a string via streambuf_iterator
  • getting file size via seeking, then preallocating a string to read into
  • getting file size via stat(), then ditto…


Continue Reading »

Reviews 02 Jan 2011 02:14:51

BioShock

BioShock for PC from Steam.

In a word: Underwhelming.

I expected so much more from this game, and it failed in every way. Weapons are boring, plasmids are bland and don’t feel very powerful, enemies are annoying and get really old really fast, scripted events are predictable, story totally failed to capture me, and the environment is almost exactly opposite of what I want.

I got all that from the 1.5 hours I spent playing it. And then I watched the Spoiler Warning play-through of it which confirmed my assumptions; it is simply not a game I would ever enjoy. Maybe if they juiced up the plasmids a lot and let the “mana” regenerate on its own…

Reviews 02 Jan 2011 01:37:26

Star Wars: The Force Unleashed

Star Wars: The Force Unleashed for PC from Steam, played with keyboard and mouse.

Looks great, but the controls are awful. Hitting your target with a force thrown object is basically random chance. And switching to 2D mode for boss battles makes them stupidly difficult…suddenly, all that you learned playing in the 3D mode is taken away and you’re put in a platformer, only with even more broken controls; you think you’re about to Force Lightning the boss, and it just fizzles right next to them. And to top it all off, there are quick time events…

This could have been an awesome game if they fixed the controls and removed the QTEs, but as it is the controls ruin the experience.

For a longer review, this guy tells it like it is.

C++ 14 Apr 2010 20:41:21

C++ dynamic_cast Performance

(Updated 2010-10-27: Re-run the test with latest clang++ from subversion)

A performance comparison of the speed of dynamic_cast operations in C++.

Idea from http://www.nerdblog.com/2006/12/how-slow-is-dynamiccast.html, who did not provide any source so I wrote my own more extensive tests.

Sources

Things Tested

  • reinterpret_cast on a known type
  • virtual function call + reinterpret_cast
  • member variable access + reinterpret_cast
  • successful dynamic_cast to its own type
  • successful dynamic_cast from the derived levels to lower levels
  • failed dynamic_cast from the derived levels to an unrelated type


Continue Reading »

« Previous PageNext Page »