Показать сообщение отдельно
Старый 20.01.2017, 11:38   #20  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA
Цитата:
Сообщение от Logger Посмотреть сообщение
Ваня, может выложишь джоб сюда ?
Привинтим еще StringBuilder и сравним.
X++:
class RunnableClass1
{        
    const int StringSite = 100000;

	public static Int64 PlusEquals()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

        stopWatch.Restart();
        str s;
        for (int i = 1; i <= StringSite; i+=5)
        {
            s += int2Str(i);
            s += int2Str(i+1);
            s += int2Str(i+2);
            s += int2Str(i+3);
            s += int2Str(i+4);
        }

        var runtime = stopWatch.ElapsedMilliseconds;
        stopWatch.Stop();

        return runtime;
    }

    public static Int64 Plus()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

        stopWatch.Restart();
        str s;
        for (int i = 1; i <= StringSite; i+=5)
        {
            s = s + int2Str(i) + int2Str(i+1) + int2Str(i+2) + int2Str(i+3) + int2Str(i+4);
        }

        var runtime = stopWatch.ElapsedMilliseconds;
        stopWatch.Stop();

        return runtime;
    }

    public static Int64 ThruStrFmt()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

        stopWatch.Restart();
        str s;

        for (int i = 1; i <= StringSite; i+=5)
        {
            s = strFmt('%1%2%3%4%5%6', s, int2Str(i), int2Str(i+1), int2Str(i+2), int2Str(i+3), int2Str(i+4));
        }

        var runtime = stopWatch.ElapsedMilliseconds;
        stopWatch.Stop();

        return runtime;
    }

    public static Int64 ThruTextBuffer()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();

        stopWatch.Restart();

        TextBuffer tb = new TextBuffer();

        for (int i = 1; i <= StringSite; i+=5)
        {
            tb.appendText(int2Str(i));
            tb.appendText(int2Str(i+1));
            tb.appendText(int2Str(i+2));
            tb.appendText(int2Str(i+3));
            tb.appendText(int2Str(i+4));
        }

        tb.getText();

        var runtime = stopWatch.ElapsedMilliseconds;
        stopWatch.Stop();

        return runtime;
    }

    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {   
        Box::info("START");
        info(strFmt("+= took %1 ms", RunnableClass1::PlusEquals()));
        info(strFmt("+ took %1 ms", RunnableClass1::Plus()));
        info(strFmt("strFmt took %1 ms", RunnableClass1::ThruStrFmt()));
        info(strFmt("TextBuffer took %1 ms", RunnableClass1::ThruTextBuffer()));
        Box::info("DONE");
    }

}
За это сообщение автора поблагодарили: Logger (5), Товарищ ♂uatr (1).