{"id":326,"date":"2008-03-30T02:04:30","date_gmt":"2008-03-30T06:04:30","guid":{"rendered":"http:\/\/www.rakkar.org\/blog\/?p=326"},"modified":"2008-03-30T02:04:30","modified_gmt":"2008-03-30T06:04:30","slug":"pretty-fast-string-class","status":"publish","type":"post","link":"https:\/\/rakkar.org\/blog\/index.php\/2008\/03\/30\/pretty-fast-string-class\/","title":{"rendered":"Pretty fast string class"},"content":{"rendered":"<p>\t\t\t\tI wrote my own string class, that is 5X faster than std::string for creation and 2X faster for copying. However, it is slower if I create a string that was previously deleted. I&#8217;m not sure what they are doing, but in that case creation is 2X faster than mine.<\/p>\n<p>It would be really cool if I could get it faster in all cases.<\/p>\n<p>Here&#8217;s the code:<br \/>\n<a HREF=\"http:\/\/raknetjenkinsso.svn.sourceforge.net\/viewvc\/raknetjenkinsso\/trunk\/Source\/RakString.cpp?view=markup\">RakString.cpp<\/a><br \/>\n<a HREF=\"http:\/\/raknetjenkinsso.svn.sourceforge.net\/viewvc\/raknetjenkinsso\/trunk\/Source\/RakString.h?view=markup\">RakString.h<\/a><\/p>\n<p><b>Times are in milliseconds<\/b><br \/>\n<i>Ref is just inserting a number, to show the speed of the list itself.<\/i><br \/>\n<i>Rak is my string<\/i><br \/>\n<i>Std is the std::string<\/i><\/p>\n<p>Insertion 1 Ref=0 Rak=25, Std=102<br \/>\nRemoveHead Ref=106 Rak=4964, Std=8577<br \/>\nInsertion 2 Ref=1 Rak=22, Std=12<br \/>\nRemoveTail Ref=0 Rak=0, Std=0<\/p>\n<p>Insertion 1 Ref=1 Rak=24, Std=102<br \/>\nRemoveHead Ref=107 Rak=4868, Std=8585<br \/>\nInsertion 2 Ref=0 Rak=23, Std=13<br \/>\nRemoveTail Ref=0 Rak=0, Std=0<\/p>\n<p>Insertion 1 Ref=1 Rak=25, Std=104<br \/>\nRemoveHead Ref=107 Rak=4879, Std=8553<br \/>\nInsertion 2 Ref=0 Rak=22, Std=13<br \/>\nRemoveTail Ref=0 Rak=0, Std=0<\/p>\n<p><b>Test code<\/b><\/p>\n<pre>\nstatic const int repeatCount=15000;\nDataStructures::List<rakstring> rakStringList;\nDataStructures::List<std ::string> stdStringList;\nDataStructures::List<char *> referenceStringList;\nunsigned i;\nRakNetTime beforeReferenceList, beforeRakString, beforeStdString, afterStdString;\n\nbeforeReferenceList=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\treferenceStringList.Insert(0);\nbeforeRakString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\trakStringList.Insert(\"Aalsdkj alsdjf laksdjf ;lasdfj ;lasjfd\");\nbeforeStdString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\tstdStringList.Insert(\"Aalsdkj alsdjf laksdjf ;lasdfj ;lasjfd\");\nafterStdString=RakNet::GetTime();\nprintf(\"Insertion 1 Ref=%i Rak=%i, Std=%i\\n\", \nbeforeRakString-beforeReferenceList, \nbeforeStdString-beforeRakString,\n afterStdString-beforeStdString);\n\nbeforeReferenceList=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\treferenceStringList.RemoveAtIndex(0);\nbeforeRakString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\trakStringList.RemoveAtIndex(0);\nbeforeStdString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\tstdStringList.RemoveAtIndex(0);\nafterStdString=RakNet::GetTime();\nprintf(\"RemoveHead Ref=%i Rak=%i, Std=%i\\n\",\n beforeRakString-beforeReferenceList,\n beforeStdString-beforeRakString,\n afterStdString-beforeStdString);\n\nbeforeReferenceList=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\treferenceStringList.Insert(0);\nbeforeRakString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\trakStringList.Insert(\"Aalsdkj alsdjf laksdjf ;lasdfj ;lasjfd\");\nbeforeStdString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\tstdStringList.Insert(\"Aalsdkj alsdjf laksdjf ;lasdfj ;lasjfd\");\nafterStdString=RakNet::GetTime();\nprintf(\"Insertion 2 Ref=%i Rak=%i, Std=%i\\n\",\n beforeRakString-beforeReferenceList,\n beforeStdString-beforeRakString,\n afterStdString-beforeStdString);\n\nbeforeReferenceList=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\treferenceStringList.RemoveAtIndex(referenceStringList.Size()-1);\nbeforeRakString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\trakStringList.RemoveAtIndex(rakStringList.Size()-1);\nbeforeStdString=RakNet::GetTime();\nfor (i=0; i < repeatCount; i++)\n\tstdStringList.RemoveAtIndex(stdStringList.Size()-1);\nafterStdString=RakNet::GetTime();\nprintf(\"RemoveTail Ref=%i Rak=%i, Std=%i\\n\",\n beforeRakString-beforeReferenceList, \nbeforeStdString-beforeRakString, \nafterStdString-beforeStdString);\n<\/pre>\n<p><\/char><\/std><\/rakstring>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wrote my own string class, that is 5X faster than std::string for creation and 2X faster for copying. However, it is slower if I create a string that was previously deleted. I&#8217;m not sure what they are doing, but in that case creation is 2X faster than mine. It would be really cool if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=326"}],"version-history":[{"count":0,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"wp:attachment":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}