Advertisement
Gaddy

StringFast - test

Dec 31st, 2015
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1.     private StringFast m_strCustom = new StringFast( 64 );
  2.     private System.Text.StringBuilder m_strBuilder = new System.Text.StringBuilder( 64 );
  3.     private delegate string Test();
  4.  
  5.     private string String_Added()
  6.     {
  7.         string str = "PI=" + Mathf.PI + "_373=" + 373;
  8.         return str.Replace( "373", "5428" );
  9.     }
  10.     private string String_Concat()
  11.     {
  12.         return string.Concat( "PI=", Mathf.PI, "_373=", 373 ).Replace( "373", "5428" );
  13.     }
  14.     private string StringBuilder()
  15.     {
  16.         m_strBuilder.Length = 0;
  17.         m_strBuilder.Append( "PI=" ).Append( Mathf.PI ).Append( "_373=" ).Append( 373 ).Replace( "373", "5428" );
  18.         return m_strBuilder.ToString();
  19.     }
  20.     private string CustomCString()
  21.     {
  22.         m_strCustom.Clear();
  23.         m_strCustom.Append( "PI=" ).Append( Mathf.PI ).Append( "_373=" ).Append( 373 ).Replace( "373", "5428" );
  24.         return m_strCustom.ToString();
  25.     }
  26.     private void RunTest( string testName, Test test )
  27.     {
  28.         Profiler.BeginSample( testName );
  29.         string lastResult = null;
  30.         for( int i=0; i<1000; i++ )
  31.             lastResult = test();
  32.         Profiler.EndSample();
  33.         //Debug.Log( "Check test result: test=" + testName + " result='" + lastResult + "' (" + lastResult.Length + ")" );
  34.     }
  35.  
  36.     private void RunTests()
  37.     {
  38.         Debug.Log( "=================" );
  39.         RunTest( "Test #1: string (+)       ", String_Added );
  40.         RunTest( "Test #2: string (.concat) ", String_Concat );
  41.         RunTest( "Test #3: StringBuilder    ", StringBuilder );
  42.         RunTest( "Test #4: custom StringFast", CustomCString );
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement