Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string_cast benchmark #2073

Merged
merged 2 commits into from
May 26, 2018
Merged

Add string_cast benchmark #2073

merged 2 commits into from
May 26, 2018

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented May 10, 2018

Benchmark various ways of dealing with int->string/string->int conversion.

Example output:

int_atoi,50331648,0.000000019404922,0.000000022758229,0.000000019926271,44,52,45
int_lexical_cast,11534336,0.000000086763293,0.000000091805305,0.000000088044255,199,211,202
strings_1_itostr,1966080,0.000000513366103,0.000000535408617,0.000000521111118,1182,1233,1200
strings_1_lexical_cast,4718592,0.000000208921847,0.000000232099410,0.000000228008503,481,534,525
strings_1_to_string,10485760,0.000000100358648,0.000000102645799,0.000000100982948,231,236,232
strings_2_multi_itostr,360448,0.000002753280569,0.000003013919923,0.000002918795376,6343,6943,6724
strings_2_multi_lexical_cast,786432,0.000001085310942,0.000001406770025,0.000001326184550,2500,3241,3055
strings_2_multi_to_string,1441792,0.000000722397090,0.000000758904207,0.000000734721074,1664,1748,1692
strings_2_strptintf,589824,0.000001733627869,0.000001917891495,0.000001835428621,3994,4418,4228

atoi and to_string (including concatenation of multiple items) seems to be the fastest option on my machine.

Somewhat complementary to #2072

@UdjinM6 UdjinM6 added this to the 12.3 milestone May 10, 2018
@kxcd
Copy link

kxcd commented May 12, 2018

Hi @UdjinM6 , why not use the stringstream library for conversion from number to string? eg this function.

template <typename T>
string NumberToString(T Number){
	ostringstream oss;
	oss << Number;
	string s = oss.str();
	return s;
}

@UdjinM6
Copy link
Author

UdjinM6 commented May 12, 2018

Added suggested test. New results:

int_atoi,54525952,0.000000019187723,0.000000020333289,0.000000019527621,44,46,44
int_lexical_cast,11534336,0.000000087266926,0.000000093114977,0.000000088241057,201,214,203
strings_1_itostr,1966080,0.000000521271431,0.000000540641850,0.000000528914340,1200,1245,1218
strings_1_lexical_cast,4718592,0.000000200056093,0.000000250434823,0.000000233503720,460,576,537
strings_1_numberToString,2621440,0.000000394880772,0.000000445743353,0.000000415233990,909,1026,956
strings_1_to_string,10485760,0.000000099870704,0.000000117348691,0.000000104061701,230,270,239
strings_2_multi_itostr,360448,0.000002743763616,0.000002986227628,0.000002932206288,6321,6880,6755
strings_2_multi_lexical_cast,786432,0.000001107924618,0.000001390930265,0.000001324080282,2552,3204,3050
strings_2_multi_numberToString,458752,0.000002188346116,0.000002595712431,0.000002322154614,5041,5980,5350
strings_2_multi_to_string,1310720,0.000000747084414,0.000000861427907,0.000000764622564,1721,1984,1761
strings_2_strptintf,589824,0.000001804815838,0.000002314453013,0.000001858364461,4158,5332,4281

to_string is still the best one on my machine.

@gladcow
Copy link

gladcow commented May 13, 2018

ACK, my results (gcc 7.3.0, Ubuntu 18):

int_atoi,251658240,0.000000003801944,0.000000004374556,0.000000004149028,8,9,9
int_lexical_cast,37748736,0.000000026969417,0.000000033025231,0.000000029328191,59,72,64
strings_1_itostr,2097152,0.000000451080268,0.000000555111001,0.000000508656058,990,1218,1116
strings_1_lexical_cast,20971520,0.000000045198249,0.000000052876430,0.000000051077893,99,116,112
strings_1_numberToString,2359296,0.000000439768883,0.000000501906470,0.000000466112801,965,1101,1023
strings_1_to_string,9437184,0.000000103829279,0.000000119913238,0.000000108923486,227,263,239
strings_2_multi_itostr,360448,0.000002510467311,0.000003486631613,0.000002851645563,5510,7653,6259
strings_2_multi_lexical_cast,2097152,0.000000377578544,0.000000560081389,0.000000478372158,828,1229,1050
strings_2_multi_numberToString,327680,0.000002153799869,0.000003418790584,0.000003094021667,4727,7504,6791
strings_2_multi_to_string,1310720,0.000000636917321,0.000000819260094,0.000000769891994,1398,1798,1689
strings_2_strptintf,917504,0.000000909256414,0.000001291084118,0.000001130077830,1995,2833,2480

@UdjinM6 UdjinM6 requested a review from nmarley May 19, 2018 06:59
@nmarley
Copy link

nmarley commented May 19, 2018

ACK, results on my machine:

#Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
int_atoi,402653184,0.000000002439265,0.000000002725031,0.000000002531824,7,8,7
int_lexical_cast,37748736,0.000000026514499,0.000000029156581,0.000000027592099,82,90,85
strings_1_itostr,3670016,0.000000260559318,0.000000292529876,0.000000283866614,806,905,878
strings_1_lexical_cast,23068672,0.000000042560714,0.000000046330911,0.000000045335861,131,143,140
strings_1_numberToString,4194304,0.000000240572263,0.000000267158612,0.000000253201733,744,827,783
strings_1_to_string,10485760,0.000000093335984,0.000000100010993,0.000000097110660,288,309,300
strings_2_multi_itostr,655360,0.000001461157808,0.000001609023457,0.000001529570000,4523,4981,4735
strings_2_multi_lexical_cast,3407872,0.000000305561116,0.000000327201633,0.000000317731694,946,1013,983
strings_2_multi_numberToString,786432,0.000001181877451,0.000001402939233,0.000001303474467,3659,4343,4035
strings_2_multi_to_string,1835008,0.000000559066393,0.000000612424628,0.000000576249736,1730,1896,1784
strings_2_strptintf,851968,0.000001143522240,0.000001270400389,0.000001198567099,3540,3933,3710

@UdjinM6 UdjinM6 merged commit 5d057cf into dashpay:develop May 26, 2018
Yoyae pushed a commit to monacocoin-net/monoeci-core that referenced this pull request May 28, 2018
* Add string_cast benchmark

* add NumberToString
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
* Add string_cast benchmark

* add NumberToString
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Mar 1, 2019
* Add string_cast benchmark

* add NumberToString
@UdjinM6 UdjinM6 deleted the stringbench branch November 26, 2020 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants