Здравствуйте, Denis2005, Вы писали:
Обожаю бенчмарки
Померил с использованием таймеров (чтобы не учитывать JIT компиляцию)
Вот результаты (усреднены по 10 запускам)
(Athlon XP 1700+ @ 1.5 GHZ + 512Mb DDR266)
:
1) DMD — 0.775 сек
2) GDC — 0.905 сек
3) С#/Nemerle — 1.1 сек
4) Python — 3.48 сек
5) Python+Psyco — 4.12 (не ускорил!)
6) GCC + Boost — 22.5 сек
7) MS VC++ + Boost — 35 сек
Компиляторы:
DMD — Digital Mars D 0.166
GDC — GNU D Compiler 0.19 для MinGW 3.4.2
C# — MS C# Compiler в составе VS2005
Nemerle — 0.9.3.99(svn) (от 12.09)
Python 2.4.2
Python 2.4.2 + Psyco 1.5
GCC — GCC 3.4.2 (в виде MinGW) + Boost 1.33.1
MS VC++ — MS C++ Compiler в составе VS2005 + Boost 1.33.1
Опции:
dmd -O -release -inline -ofsplit-d.exe split.d
gdc split.d -O99 -osplit-gdc.exe
csc /o+ /out:split-cs.exe split.cs
ncc -out:split-n.exe split.n
g++ split.cpp -
If:/boost -O99 -osplit-gpp
сl split.cpp /Ox /Oi /Ot /GT /GL /I "F:\boost" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D_SECURE_SCL=0 /D "_UNICODE" /D "UNICODE" /FD /EHsc /MD /GS- /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt
/Fesplit-cpp.exe
Исходники:
D:
import std.stdio, std.string, std.perf;
void main()
{
auto t = new HighPerformanceCounter();
t.start();
uint res = 0;
for(uint i = 0; i < 1000000; ++i)
res += split("123 345 asdf 23453 asdfas"," ").length;
t.stop();
writefln("res is ", res ," ", t.milliseconds()," ms elapsed.");
}
C#:
using System;
using System.Diagnostics;
class Runner
{
public static void Main()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
int res = 0;
for(uint i = 0; i < 1000000; ++i)
res += "123 345 asdf 23453 asdfas".Split(' ').Length;
stopwatch.Stop();
Console.WriteLine("res is {0}, {1} elapsed",
res, stopwatch.Elapsed);
}
}
Nemerle:
using System.Console;
using System.Diagnostics;
def stopwatch = Stopwatch();
stopwatch.Start();
mutable res = 0;
repeat(1000000)
res += "123 345 asdf 23453 asdfas".Split(' ').Length;
stopwatch.Stop();
WriteLine($"res is $res, $(stopwatch.Elapsed) elapsed");
Python:
import time
start = time.clock()
res = 0
for i in xrange(1000000):
res += len("123 345 asdf 23453 asdfas".split(" "))
finish = time.clock()
print 'res is %s, %f sec elapsed' % ( res, finish - start )
Python+Psyco:
import time
import psyco
psyco.full()
start = time.clock()
res = 0
for i in xrange(1000000):
res += len("123 345 asdf 23453 asdfas".split(" "))
finish = time.clock()
print 'res is %s, %f sec elapsed' % ( res, finish - start )
С++:
#include <vector>
#include <string>
#include <iostream>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <windows.h> // for GetTickCount
using namespace std;
using namespace boost::algorithm;
int main()
{
DWORD start = GetTickCount();
int res = 0;
for(int i = 0; i < 1000000; i++)
{
// так корректней сравнивать, ведь в др программах мы размер не указывали
// + по моим тестам почти не повлияло на скорость
vector<string> tokens;
split(tokens, "123 345 asdf 23453 asdfas", is_any_of(" "));
res += tokens.size();
}
DWORD stop = GetTickCount();
cout << "res is " << res << ',' << stop - start << " ms elapsed\n";
return 0;
}