PHP中不需要StringBuilder模拟。我做了几个简单的测试:在PHP中:$iterations = 10000;$stringToAppend = 'TESTSTR';$timer = new Timer(); // based on microtime()$s = '';for($i = 0; $i < $iterations; $i++){ $s .= ($i . $stringToAppend);}$timer->VarDumpCurrentTimerValue();$timer->Restart();// Used purlogic's implementation.// I tried other implementations, but they are not faster$sb = new StringBuilder(); for($i = 0; $i < $iterations; $i++){ $sb->append($i); $sb->append($stringToAppend);}$ss = $sb->toString();$timer->VarDumpCurrentTimerValue();在C#(.NET 4.0)中:const int iterations = 10000;const string stringToAppend = "TESTSTR";string s = "";var timer = new Timer(); // based on StopWatchfor(int i = 0; i < iterations; i++){ s += (i + stringToAppend);}timer.ShowCurrentTimerValue();timer.Restart();var sb = new StringBuilder();for(int i = 0; i < iterations; i++){ sb.Append(i); sb.Append(stringToAppend);}string ss = sb.ToString();timer.ShowCurrentTimerValue();结果:10000次迭代:1)PHP,普通串联:〜6ms2)PHP,使用StringBuilder:〜5 ms 3)C#,普通串联:〜520ms4)C#,使用StringBuilder:〜1ms100000次迭代:1)PHP,普通串联:〜63ms2)PHP,使用StringBuilder:〜555ms3)C#,普通串联:〜91000ms // !!!4)C#,使用StringBuilder:〜17ms