Showing posts with label speed. Show all posts
Showing posts with label speed. Show all posts

Thursday, 19 July 2018

C++ : Copy Constructor versus Ignorance

I've spent a bit of time reviewing someone else's code recently and I've come to an impasse with them, so they have a lot of code which will take some standard container, and the code doesn't just initialise the local copy from the passed in reference... No it'll iterate over the list of elements adding them to the class version.

I have picked fault with this, it's not RAII, it looks ugly and if you're threading you can create your class instance and the member is empty or in a partially filled state before the loop within the constructor is finished... I highlight this in red below...

My solution?  Just initialise the member from the reference - see the green highlight in the code below.

My results from the timing below?



These times are "microseconds" so tiny... But with just constructing from the existing reference we always get a lower time, quicker code...


Running this test 30,000 times, trying it in different orders and with maps of upto 1000 elements I had a rough average increase of 60% speed by using the copy constructor of std::map rather than reallocating new memory for each pre-existing element.

I wanted therefore to understand the reasoning behind the original code, was there some reason to perform a clone (alloc and assign new instance) operation for each pair in the map being passed in?  Looking at the code there was no apparent reason, so I spoke to the developer, asking why they had performed the construction in this manner... Their reply...

"That's how you initialise a container"

You can load up a container in this manner, but you already have the contents of the map, you're just copying it... "Why don't you use the copy constructor?"... I asked...

"I didn't write one"

Hmm, "You don't, the compiler generates it for you, std::map has its own copy constructor".  Use the copy constructor folks, trust me.


#include <map>
#include <chrono>
#include <string>
#include <iostream>


using Mapping = std::map<int, int>;

class A
{
private:
Mapping m_TheMapping;

public:

A() = delete;
A(const A&) = delete;
void operator=(const A&) = delete;

A(const Mapping& p_Mapping)
:
m_TheMapping(p_Mapping)
{
}

A(const Mapping& p_Mapping, const bool& p_Other)
:
m_TheMapping()
{
for (auto i : p_Mapping)
{
m_TheMapping.emplace(i);
}
}

inline Mapping& Mapping()
{
return m_TheMapping;
}
};


int main()
{
Mapping l_m
{
{ 0, 0 },
{ 1, 1 },
{ 2, 2 },
{ 3, 3 }
};

auto l_time(std::chrono::high_resolution_clock::now());
// Copy Construction
A l_map(l_m);
auto l_timeB(std::chrono::high_resolution_clock::now());

auto l_Dur(l_timeB - l_time);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_Dur).count() << std::endl;


auto l_time2(std::chrono::high_resolution_clock::now());
// Clone Construction
A l_map2(l_m, true);
auto l_time2B(std::chrono::high_resolution_clock::now());

auto l_DurB(l_time2B - l_time2);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_DurB).count() << std::endl;
}

Tuesday, 12 June 2018

CPU Speed : That Time I got Conned

As a technologist I've always been interested in the newest kit coming out, and many moons ago this exact demand for kit made me very mad.

For you see, the previous year I'd built my first 2 ghz machine, and it was very costly.  Hyper threading was new to the market, at least in the Pentium 4 range.  And as usual I had need for more power from my machines.

So I hit the interwebs and found a machine (on ebay I think) which was 2ghz... A nice CPU was mentioned in the specification... But the memory and graphics capability were lacking...

I could make the difference up from my spares bin, so I took the dive ordering this machine as a base on which to work.

It duely arrived, I plugged it in, and was dismayed to find it clocking only around 1.1 ghz.  Baffled, I check the advert, "Dual core 2 ghz chip" was definiately there, with the sub-note "exact type may vary, select Intel or AMD preference".

Back to the machine it is dual core, but it is not 2 ghz, no where near.  So I call them up...  Not even have I explained and the phone was put down on me.

Maybe, just maybe it was a mistake, I call again... Phone rings unanswered.

Paypal dispute time as I pack this machine back up into it's box.

Except, the seller won't refund nor accept a return.  They have meticulos pictures of the machine and documents stating that it's correct and I'm trying to con them...!

The ebay resolution center rule in their favour, I'm obliged to accept the item.  I forget the details exactly, but it was a very protracted affair.  All whilst the machine say unused and I started to build an actual second 2ghz machine for myself.

After about four weeks though, I get the resolution center ruling, and accepting the fact I have this potato (it was still a good price for the potato, just not the fabulous deal I thought I had gotten)...

But one of the documents catches my eye, it said:

"2ghz speed is from our including two processors of at least 1ghz speed"

and in pencil of this digitized photo of the page they've put the processor spec and the maths... 2 x 1.1ghz = 2.2 ghz faster than they had paid for.

You know and I know that's not how processor speeds work, but ebay had accepted it, the conners at the other end of this sham had me very very annoyed by this....

However, whenever I seek people bemoaning the 5ghz tests being carried out by Intel, with external hidden sub-ambient coolers helping, I can't ever stop the phrase... "that's 2.5ghz x 2 easy"... Or thinking my current machine at home is a 48ghz speed (12 x 4ghz).

Wednesday, 31 January 2018

C++ boost::replace_all Slowed Me

I've just had myself into a complete frazzle, code yesterday was fast, rendering 120fps, the same code today was struggling to pass 11fps.  And it had me pulling my hair out, of which I have little left to spare.

The problem?

I had been processing strings for specific patterns and only replacing them, so a variable in my engine might have the value "SCORE" and it'd replace the players score value directly into the std::string instance for display.

I however decided I wanted to compound all these reserved words to allow any value to contain any replaced value and also contain formatting, so I could so something like "You have scored %SCORE% today" and it'd just place the number in place.

I turned to boost for this, boost::replace_all, to be specific, and I had about 45 pattern matches which would try to replace any instance of the string in place.

However, this function does not look a head if the predicate is present in the source string, it's in fact very slow.

So code:

const std::string l_Pattern("%SCORE%");
std::string l_Source("You have scored %SCORE% today");
.
.
.
boost::replace_all(
    l_Source,
    l_Pattern,
    Player::Instance()::ScoreAsString());

Would result in very slow performance, my solution is not perform the replace... search for the pattern predicate first:

if ( l_Scource.find(l_Pattern) != std::string::npos )
{
    boost::replace_all(
        l_Source,
        l_Pattern,
        Player::Instance()::ScoreAsString());
}

This latter code runs so much more quickly, I'm far in a way back a head of the speed curve, but I have this lovely dynamic placing of the variables into my rendering controls, and any control can receive any value just by my tweaking the loaded display script, so neat....

Anyway, I hope that helps.  If you want to help me, pop over to my YouTube channel and hit that subscribe button.

Wednesday, 15 November 2017

Time Expectations in WoW Classic?

With the news today of EA reducing by 75% the time it will take in Star Wars Battlefront 2 to unlock a hero character, can we expect to see modern gamers head into WoW Classic and start complaining?

(c)2017 Electonic Arts

Lets just recap though, World of Warcraft, vanilla, people played a character to level 60 in about 4 days played, that's about 96 hours played.

EA's plight, and collapse into pandering, happened with a played time of around 40, that's less than half... Reducing it by 75% that now makes a hero in SW:BF2 in 10 hours.

10 hours for Vanilla WoW was not enough, and this is where my first concerns with WoW Classic come about, firstly, will Blizzard be forced to pander down to newer gamers whom most certainly want action & reaction, risk and reward.  They certainly don't deal in patience nor RNG.

My second concern comes that this is a big issue, and perhaps Blizzard will side step it, by simple nerfing the amount of time to level, or perhaps increasing the rate of XP gain, as arguably since Burning Crusade or Wrath of the Litch King, the business model for WOW has been to push players to level cap as fast as possible and explore repetitive tasks in that area.

The way of thinking Blizzard have entertained (no pun intended) since I stopped playing was daily's, and find a group, find a raid, tokens, faster reward for input, but with exponential damage, health and other stats making that power-wonder factor... Fast rewards, I said during my appearance on "Shut Up We're Talking" that this was where things would be going.

Rinse and repeat.  That is all I've seen delivered, it's certainly all I've heard explained.  Should I name drop "Garrisons"?

All this said however, we must remember, that there will be a huge influx of tourists to WoW Classic, toe dabblers, so what could the population of regulars; the hardcore; who settle there expect?  These are the things we don't know and as you can tell by this post, we can only speculate about.

Sunday, 12 November 2017

Virgin Media - Poor Internet Speed Measured

Phase one of my plan is now complete, I have monitored the speed of my internet ALLLL day, from just after I got home in the morning, through until just now.

No-other unit or device was being used through from around 4pm until just now - the wife and I went to watch the new Thor film at the cinema - so, how can Virgin Media explain that clear throttling down mid-afternoon...

It is awful and far below anything listed on their website, utter and total garbage speed.  Yet we see a general level of 25+ for most of the day

You will need to click this chart to see the image close up.

My data points were taken with my script - see the previous post - every 10 seconds, it has generally used resolved to the Server in Leeds.

The time markers (green) were added by myself, artificially, by eye.  But they give you the gist of the time, and I will also upload the raw CSV somewhere...

I am now going to hit twitter.



Edit - This is fabulous, I've just gone to the link I was provided to send info to Virgin, and this is what happens....

That was the page I wanted.... And the same message appears if one tries to see the local service status!

This really is getting criminal, no-one would be able to run a business on this kind of service, no-one could perform research or educational activities, and I can't work in my technology areas of interest at all... And complaining has resulted in nothing but indifference and stagnation.

Friday, 10 November 2017

Virgin Media : Poor Internet Speed Misery

You know that moment in Misery where Annie (played by the excellent Kathy Bates) raises the lump hammer to Paul (James Caan's) ankles?  That hopeless moment, where you know what's coming, and she's determined this is the best, and he's helpless to change things....


Yeah, his feeling at that moment is the same feeling I get whenever I try to solve my service problems with Virgin Media.  I've tried in the phone centre, they either won't talk to me, or deny I'm an account holder - the account being in my wifes name, but I'm a registered up user of the account etc etc.... Or they simply deny there's an issue....

"I can ping you now sir"....

Really, a few ICMP packets get through and you think it's a-okay do you?

Or I get told, reboot your superhub...

Or variously asked "are you on wifi or wired"... It makes no difference when the speed recorded by either is less than 2mbits!!!

And I've just been told in a reply on twitter "If you have been told about an Area Issue were you given an estimate as to when the issue will be resolved"... I've not been told anything about any area issues, nothing, nada, zip.

Therefore I'm still not best pleased, remember I went down from paying through the nose for Vivid200, as I never ever got anywhere near 200mbits/sec ever.  I did record regular speeds of around 34 to 50 mbits, therefore the safer, more cost effective option was to pay for Vivid50.  Simple, see, simple logical option, if they can't meet the expectations of their own service, play the system at it's own game.

However, it seems that in reality, Vivid200 should be labelled Vivid50, and Vivid50 itself should be called Vivid1... Because breaking the 1mbit/sec barrier seems to be too much for it.

I have therefore decided to create something anyone can interpret, a chart... Managers love charts... People can interpret charts....

This chart is going to record the internet speed (recorded from my linux server, on my wired Cat5e directly to my 1gigabit router, which is directly wired to the Virgin Media Superhub 2 set into Modem Mode).  No wifi, no confusion, no bull, and my router has pfSense, so I can see there's no shenanigans, just the pure speed through put.

I'm going to record the speed with "speedtest-cli", which you can see yourself how to install here.

I will collect my results by running a python script, which runs the speed test and outputs the time, the upload and finally the download speed into a CSV file.

Find the source on my github... 

import subprocess
import time
from time import gmtime, strftime

# Open a simple text file for writing the result
resultFile = open("speedtest.txt", "a+")

while True:
# Header text & placeholders for our result
print ("Starting Test...")
timeStr = strftime("%Y-%m-%d %H:%M:%S", gmtime())
downloadSpeed = ""
uploadSpeed = ""

# Action the process to test our speed
# capturing it's output
result = subprocess.run(['speedtest-cli'], stdout=subprocess.PIPE)

# Process the output into text & split the text
# at each new line character
btext = result.stdout
text = btext.decode('ascii')
lines = text.split("\n")

# For each line, check whether it is upload
# or download
for line in lines:
# For Download, take a split against space
# and the middle value is the speed
if line.startswith('Download: '):
speedParts = line.split(" ")
if len(speedParts) == 3:
downloadSpeed = speedParts[1]
# Likewise for upload, the middle  value is
# the tested speed
elif line.startswith('Upload: '):
speedParts = line.split(" ")
if len(speedParts) == 3:
uploadSpeed = speedParts[1]

# Print our output result as a CSV
print (timeStr + "," + downloadSpeed + "," + uploadSpeed)

# Write the result to a file also
resultFile.write (timeStr + "," + downloadSpeed + "," + uploadSpeed + "\r\n")
resultFile.flush()

# Count down until the next test time
count = 10
while count > 0:
# The line is repeated, so we use the end=""
# and a return carriage to print over and over
print ("\rTime until next test " + str(count) + " seconds", end="")
time.sleep(1)
count = count - 1
# Print a new line to stop the next text appending
# on the time count down line
print()

I will then load this CSV file into a spread sheet and create a chart, here's one I created earlier with 5 test data points.


The blue-line is where I'm most concerned, that is my download speed, as you can see within three minutes I had quite a difference, ranging from a high of 2.24 mbit, to a low of 1.23 mbit.  Upload speed has been more consistent giving a measly 3.5 to 4.0 ish.

I already know where VirginMedia will take the conversation, they will talk about "based on average peak time download performance".  However, I want to immediately counter that their speed information states that speeds are based around "Movie based on 4.1GB file size a single user and wired connection", and this chart is provided.... 

Average download speed at peak time (8pm to 10pm) the time's I have mostly messaged to them on twitter are sub 1mbps... Right now at just before 11am they are still reporting as extremely low.  And yes, this server is the ONLY machine on in the house, the wifi is off, the other wire into this hub removed, there is one wire to one machine and one wire to their Superhub...

And yes, I can get 1gbit disk to disk over NFS on this hub, the wires to and from it to the machines are perfect, and I've also swapped the wire to the superhub.

I'm going to run this for a few days, and see what speeds we get in the dead of night, or early mornings, and see if there is a pattern.  I have known for years Virgin will throttle speeds, however, their table of speeds is labelled "Average", one can only believe we're on the lowest ebb of that bell curve, and I am not a happy customer.

Sunday, 5 November 2017

Virgin Media : Poor Internet Speed

I'm continuing to have my issues with Virgin Media, let me explain.  Last month I came to them asking to remove the superfluous junk offering items, as I was simply paying more for items I didn't use, want nor need.

They could not help, in fact they flat refused to, so I cancelled 66% of my services off completely, TV, Phone all gone and never ever to return - well done them...

The next item was the 200mbit broadband I was paying for, below is a historic speed test I carried out a lot, as you can see I never, ever, got near 200Mbit, but I always got over 50Mbit...


Being quite a logical person therefore, and based on this evidence, this proof I had for myself, I downgraded the internet from the Vivid200 to Vivid50, i.e. 50mbit... Yeah, save money, it can do 50 mbit easy, right... Right... RIGHT?.....

WRONG.

This is tonight's speed test...


Last night it was slower than that, I had a download speed of 1.22mbit, and upload of 620K.

Yeah, rocking the 1990's internet speed.

And I'm utterly sick of it, I'm sick of paying for a service I never ever get.  It may have been optimistic, maybe even naive to think having seen 50mbit when paying for 200, I would get 50 when paying for 50, but clearly something has gone astray here.

Clearly, Virgin Media are up to some shenanigans, be that throttling, load balancing, whatever term they want to give it, or even what ever they want to say in denial, but I'm observing this poor speed, I'm enduring this poor service, and I'm utterly and totally frustrated with the script (I would say expert system, but it's clearly a script) the people in the call centers follow.

This is NOT my equipment, this is not my network, this is their external speed, this is from their superhub 2 and outwards, NOT the internal side of that connection.

That is a test through the newer version of Ookla (the site at the top) as you can see the speed is even worse twenty minutes on - BTW, note to Virgin Media, your own engineers use this site to do a test upon installation.


And here's the speed an hour after my original post... this is now 21:32 on a Sunday evening...

Saturday, 30 April 2016

Virgin Media - Getting The Service You Require

I've had a bit of a battle with Virgin Media over the last month, I noted I was suddenly, and for no reason, on a very slow connection (at least slow to my liking) it was showing up in tests as between 46 and 52 mbit... STRANGE!  Since I thought I was on 100Mbit and was trying at the time to get onto the new Vivid200 mbit.

Anyway, after doing some calling around, and basically being given the run around by sales, I got through to a chap in the right department, who was able to sell me things AND look at my account; they seem very able to sell stuff to you, and take your money, but you ask for something and you get stone walled.

So, this chap checked my account, 50M sir, you're on our 50M service?... I thought I was on the Big Bundle thing, on the tele?.. 100Mbit etc... Oh You were sir, but your contract ended in 2016...

So, did they continue charging me?.. Oh yes.. Full whack, but they slowly eroded both the channels on the TV package and the speed of the internet, I guess hoping they could provide less and charge the same, or even more!

I set about trying to rectify this, and got exactly nowhere, online chat, telephone calls, even twitter didn't budge them into action, they didn't give a hoot!

Therefore, I set about getting what I wanted the underhanded way... 

What I wanted was to jump from 50mbit to 200mbit, leaving the TV and landline telephone as was, the problem?... No human operator on any channel, in any department, nowhere could give me this, I was even told you could not order this combination!  That my kit didn't support it!  That the wires were wrong!!?!?!

When I pointed out that the wires and kit are theirs, sort it, they basically hung up on me.

Online in my account however, I could see an upgrade offer... For a free I could upgrade to some new cables.. DOCSIS or some such thing... So, I ordered that...

A week later, I checked again, the new offer was for a free upgrade from 50mbit to 70mbit.  Are you still with me here?... So I chose that.

A week yet further on and I had 70mbit, and the option to pay £1.50 more per month to upgrade to 100mbit!  So I ordered that.

And yet another week on, I finally have the option to order 200mbit for an additional £5.50 a month, with 6 months at £2.50...


I have this arriving, through the ether as we read this...

So why the delay?  Why did the humans say they could not leave my TV and landline alone to just uprade the speed?... Well, seems they could, they could all along, they were lying, or their training didn't expose them to the workings of their own systems.  Whichever it was, I was very very frustrated by the whole affair, and I've made it known.



Sunday, 12 October 2014

Virgin Media - Long Eaton

What Internet speed am I paying for?... 60mbps... Sixty... And what am I getting?.... 

Two and a half... Yes, 2.5mbps...


I've tested this 6 times, three times with testmy.net and three times with http://www.broadbandspeedchecker.co.uk/... 

2.5mbps above is the fastest download speed I've seen returned...

It is a Sunday night, I know everyone will be in streaming movies, or browsing the web, but if the provider can't supply 60mpbs because their equipment in the area is saturated they should not advertise or charge for 60mpbs...

I can't play games, I can't watch YouTube and the live TV I just tried to watch, because the wife has fucking X-Factor on just does this:


And I don't blame it at 2.5mbps... But I pay for 60!

Virgin Media, do something about this!

Monday, 20 January 2014

C++ Integer to std::string conversion speed

There is often a lot of discussion about the most efficient way to convert things in C++, personally I like the boost::lexical_cast, I find it gives clear and readable code; very important in the systems I write, especially for maintenance and up keep.

However, many assume it to be slow, indeed most authors on the topic turn almost immediately to C for the fastest way to convert integers to strings, and unfortunately I find the same is true, even with std::string and std::ostringstream features the old sprintf tends to be faster.

But, crippling many users of std::string is their lack of understanding of that standard library staple class, so here is my little investigation into the speed of conversion, using a mix of C and standard C++, to give you a good idea of how fast things can be, and how to use your standard class and its memory to best effect.

The first trick you will see in this is the use of the std::string as a memory buffer, you can do this by declaring your standard string, then resizing it...

std::string MyName;
MyName.resize(12);

The memory location now at &MyName[0] points to 12 empty characters for you to use just as you would a char* or &char[], useful to stop using uncontrolled char* buffers left right and center, and perhaps the least used "tip" I can give when using std::string.

So, what conversions do we have?...

class Conversions
{
    public:

        static const std::string IntToString(const int& p_Input);

        static const std::string IntToString2(const int& p_Input);

        static const std::string IntToString3(const int& p_Input);

        static const char* IntToString4(const int& p_Input);

        static const void TestConversions (const int& p_Cycles);

};

The first three are going to be using whatever code to always give a pre-allocated std::string, the fourth conversion is going to return a raw char*, so the programmer has to delete the result etc, or rick a memory leak.

I still want that fourth result to be a std::string however, and I'm not going to worry about the leaking memory, so though the function performs a new[] I will not perform a delete[], but simply will assign the char* to a new std::string upon return.  Making the timings taken fairer.

So, lets look at the program code for each of the functions, and the timing in the test function.  I'm going to use boost::posix_time for the timings here:

const std::string Conversions::IntToString(const int& p_Input)
{
    std::string l_buffer;
    l_buffer.resize(33);
    sprintf(&l_buffer[0], "%d", p_Input);
    return l_buffer;
}

Above we can see the first function, using our string resizing tip, we resize the string as a buffer to take up to 33 characters (the maximum size for a 32bit integer is 33 characters) and then we use the old fashioned sprintf from the cstdlib header.  Many claim this to be the fastest, the defacto conversion, even more so than using itoa.

const std::string Conversions::IntToString2(const int& p_Input)
{
    std::ostringstream l_oss;
    l_oss << p_Input;
    return l_oss.str();
}

Next is the standard library way of working, we create a new ostringstream and stream the integer into it, then return the std::string from the stream.  I believe this to be pretty slow, my mind tells me that the creation of the stream and then the extraction of the result is going to be slow; but we shall see in a moment.

const std::string Conversions::IntToString3(const int& p_Input)
{
    char l_buffer[33];
    sprintf(l_buffer, "%d", p_Input);
    return std::string (l_buffer);
}

Next we have another use of sprintf, however, this time we're not resizing a string natively, we're creating a character string and then casting it back as a result.  I think this may be the fastest, but again we shall see.

const char* Conversions::IntToString4(const int& p_Input)
{
    char* l_buffer = new char[33];
    sprintf(l_buffer, "%d", p_Input);
    return l_buffer;
}

Finally, very similar to the third test, this conversion creates a new character array pointer as the buffer, and then uses sprintf.  This is going to leak memory if we don't delete[], but I'm ignoring that for now and just testing the speed.

Now onto the conversion test function, the basic layout is, take the start time before the conversion, call the conversion a lot of times assigning the result to a std::string locally, and then take the time after and output the difference in milliseconds...

Now, the speed of this code in C++ is going to be fast in all cases, so we need enough sample calls to get a reading... I'm settling on 30 million calls, 30000000.

const void Conversions::TestConversions (const int& p_Cycles)
{
    // Test 1
    std::cout << "Test 1...";
    boost::posix_time::ptime l_end;
    boost::posix_time::ptime l_start (boost::posix_time::second_clock::local_time());
    std::string l_result;
    for (int i = 0; i < p_Cycles; ++i)
    {
        l_result = IntToString(i);
    }
    l_end = boost::posix_time::second_clock::local_time();
    boost::posix_time::time_duration l_diff = l_end - l_start;
    std::cout << l_diff.total_milliseconds() << std::endl;

    // Test 2
    std::cout << "Test 2...";
    l_start = boost::posix_time::second_clock::local_time();
    for (int i = 0; i < p_Cycles; ++i)
    {
        l_result = IntToString2(i);
    }
    l_end = boost::posix_time::second_clock::local_time();
    l_diff = l_end - l_start;
    std::cout << l_diff.total_milliseconds() << std::endl;

    // Test 3
    std::cout << "Test 3...";
    l_start = boost::posix_time::second_clock::local_time();
    for (int i = 0; i < p_Cycles; ++i)
    {
        l_result = IntToString3(i);
    }
    l_end = boost::posix_time::second_clock::local_time();
    l_diff = l_end - l_start;
    std::cout << l_diff.total_milliseconds() << std::endl;

    // Test 4
    std::cout << "Test 4...";
    l_start = boost::posix_time::second_clock::local_time();
    for (int i = 0; i < p_Cycles; ++i)
    {
        l_result = IntToString4(i);
    }
    l_end = boost::posix_time::second_clock::local_time();
    l_diff = l_end - l_start;
    std::cout << l_diff.total_milliseconds() << std::endl;
}

Lets see what our output is:

Test1...6000
Test2...17000
Test3...5000
Test4...6000

Immediately we can see my hunch about using the string stream is correct, its very much slower, more than twice as slow.

Surprisingly, at least to most readers - one hopes - we can see that the string::resize and use of sprintf is very close to the other uses of sprintf.

Since sprintf should be taking a constant amount of time what we've timed in tests 1, 3 and 4 is the speed of our memory management, how quickly has the function made the result available.

Some readers maybe screaming at me to use itoa, and one could do that with a char buffer, or even a resized string, thus:

std::string buffer;
buffer.resize(33);
itoa (&buffer[0], p_Input, 10);

However, itoa is not a standard function and some compilers don't supply it, therefore you must generally always use the lowest common denominator and sprintf is just that.

There is also one last avenue, the lexical cast...

// Test 5
std::cout << "Test 5...";
l_start = boost::posix_time::second_clock::local_time();
for (int i = 0; i < p_Cycles; ++i)
{
    l_result = boost::lexical_cast<int>(i);
}
l_end = boost::posix_time::second_clock::local_time();
l_diff = l_end - l_start;
std::cout << l_diff.total_milliseconds() << std::endl;

Now, this approach should take into account the "bad_lexical_cast" exception, but exception handling is slow so we're ignoring that at this juncture.  And assuming we have a known data source (int i) which we have in a valid range.

Our test results how are similar for the original calls...

Test 1...6000
Test 2...17000
Test 3...5000
Test 4...5850

The new fifth test...

Test 5...1000

This is very much quicker than any of the other solutions proposed...

So, there you go...

#include <boost/lexical_cast.hpp>
#include <boost/date_time/local_time/local_time.hpp>
#include <string>
#include <iostream>

int main ()
{
// Test 5
std::cout << "Test 5...";
boost::posix_time::ptime l_start =
boost::posix_time::second_clock::local_time();
for (int i = 0; i < p_Cycles; ++i)
{
l_result = boost::lexical_cast<int>(i);
}
boost::posix_time::ptime l_end = 
boost::posix_time::second_clock::local_time();
boost::posix_time::time_duration l_diff = l_end - l_start;
std::cout << l_diff.total_milliseconds() << std::endl;

return 0;
}

Use lexical cast...

And about the exception handling, be smart the speed of this code is not affected by making the function throw the exception up, or by making the whole loop handle the exception once, be smart... and stop mucking about with conversions in C, you're only fooling yourself they're faster than other options.