|
Алгоритмика Об алгоритмах вообще; методы, обсуждения способов решения |
29.11.2011, 00:19
|
#46
|
Дэвелопер
Регистрация: 10.09.2007
Сообщений: 1,442
Написано 793 полезных сообщений (для 1,460 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
Сообщение от HolyDel
с flatten надо просто выполнить несколько арифмитических операций, чтобы вычислить индекс, а с jagged нужны как минимум два обращения к памяти. покажи код.
|
а в случае с деревьями, надо сделать несколько прыжков по памяти в глубину дерева от корня.
это, кстати, ответ на вопрос Платона, почему деревья не подходят.
|
(Offline)
|
|
29.11.2011, 11:05
|
#47
|
☭
Регистрация: 26.09.2006
Сообщений: 6,035
Написано 1,474 полезных сообщений (для 2,707 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
да не, на верхнем уровне по любому должно быть дерево. просто на ноде дерева должен висеть не один кубик, а массив 16х16х16 например.
|
(Offline)
|
|
29.11.2011, 15:20
|
#48
|
.
Регистрация: 05.08.2006
Сообщений: 10,429
Написано 3,454 полезных сообщений (для 6,863 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
Вот снова затестил, такой результат:
Multidimensional allocate: 1.258ms
Multidimensional fill: 701.627ms
Multidimensional get 65536 times: 1.09ms
Flattened allocate: 1.751ms
Flattened fill: 212.648ms
Flattened get 65536 times: 0.331ms
Jagged allocate: 460.847ms
Jagged fill: 286.233ms
Jagged get 65536 times: 0.455ms
Вот код с тремя вариантами:
using System; using System.Diagnostics; using System.Threading; namespace speedTest { static class Program { static int Main() { int counter = 0; Stopwatch timer = new Stopwatch(); Thread.Sleep(100); { // Multidimensional long elapsedAllocation, elapsedFill, elapsedGet, number; timer.Restart(); int[,,] map = new int[512, 128, 512]; elapsedAllocation = timer.ElapsedTicks; Console.WriteLine("Multidimensional allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 20; i++) { for (int x = 0; x < 512; x++) { for (int y = 0; y < 128; y++) { for (int z = 0; z < 512; z++) { ++counter; map[x, y, z] = counter; } } } } elapsedFill = timer.ElapsedTicks; Console.WriteLine("Multidimensional fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 65536; ++i) { number = map[100, 10, 100]; } elapsedGet = timer.ElapsedTicks; Console.WriteLine("Multidimensional get 65536 times: {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3)); } Thread.Sleep(100); { // Flattened long elapsedAllocation, elapsedFill, elapsedGet, number; timer.Restart(); int[] map = new int[512 * 128 * 512]; elapsedAllocation = timer.ElapsedTicks; Console.WriteLine("Flattened allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 20; i++) { for (int x = 0; x < 512; x++) { for (int y = 0; y < 128; y++) { for (int z = 0; z < 512; z++) { ++counter; map[512 * 128 * x + 128 * y + z] = counter; } } } } elapsedFill = timer.ElapsedTicks; Console.WriteLine("Flattened fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 65536; ++i) { number = map[512*128*100+128*10+100]; } elapsedGet = timer.ElapsedTicks; Console.WriteLine("Flattened get 65536 times: {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3)); } Thread.Sleep(100); { // Jagged long elapsedAllocation, elapsedFill, elapsedGet, number; timer.Restart(); int[][][] map = new int[512][][]; for (int y = 0; y < 512; ++y) { map[y] = new int[128][]; for (int z = 0; z < 128; ++z) { map[y][z] = new int[512]; } } elapsedAllocation = timer.ElapsedTicks; Console.WriteLine("Jagged allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 20; i++) { for (int x = 0; x < 512; x++) { for (int y = 0; y < 128; y++) { for (int z = 0; z < 512; z++) { ++counter; map[x][y][z] = counter; } } } } elapsedFill = timer.ElapsedTicks; Console.WriteLine("Jagged fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3)); timer.Restart(); for (int i = 0; i < 65536; ++i) { number = map[100][10][100]; } elapsedGet = timer.ElapsedTicks; Console.WriteLine("Jagged get 65536 times: {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3)); } Console.Read(); return 0; } } }
|
(Offline)
|
|
Эти 2 пользователя(ей) сказали Спасибо moka за это полезное сообщение:
|
|
29.11.2011, 17:15
|
#49
|
☭
Регистрация: 26.09.2006
Сообщений: 6,035
Написано 1,474 полезных сообщений (для 2,707 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
оно берется с кэша! Мока!
using System;
using System.Diagnostics;
using System.Threading;
namespace speedTest
{
static class Program
{
public struct index
{
public int x, y, z;
};
static int Main()
{
int counter = 0;
int count_values = 512 * 128 * 512;
index[] ordered_values = new index[count_values];
index[] random_values = new index[count_values];
{
int x = 0, y = 0, z = 0;
Random r = new Random();
for (int i = 0; i < count_values; ++i)
{
ordered_values[i].x = z;
ordered_values[i].y = y;
ordered_values[i].z = x;
x++;
if (x > 511)
{
x = 0;
y++;
}
if (y > 127)
{
y = 0;
z++;
}
random_values[i].x = r.Next(511);
random_values[i].y = r.Next(127);
random_values[i].z = r.Next(511);
}
}
Stopwatch timer = new Stopwatch();
Thread.Sleep(100);
{ // Multidimensional
long elapsedAllocation, elapsedFill, elapsedGet, number;
timer.Restart();
int[, ,] map = new int[512, 128, 512];
elapsedAllocation = timer.ElapsedTicks;
Console.WriteLine("Multidimensional allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < 20; i++)
{
for (int x = 0; x < 512; x++)
{
for (int y = 0; y < 128; y++)
{
for (int z = 0; z < 512; z++)
{
++counter;
map[x, y, z] = counter;
}
}
}
}
elapsedFill = timer.ElapsedTicks;
Console.WriteLine("Multidimensional fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[ordered_values[i].x, ordered_values[i].y, ordered_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Multidimensional get all times (ordered): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[random_values[i].x, random_values[i].y, random_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Multidimensional get all times (random): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
}
Thread.Sleep(100);
{ // Flattened
long elapsedAllocation, elapsedFill, elapsedGet, number;
timer.Restart();
int[] map = new int[512 * 128 * 512];
elapsedAllocation = timer.ElapsedTicks;
Console.WriteLine("Flattened allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < 20; i++)
{
for (int x = 0; x < 512; x++)
{
for (int y = 0; y < 128; y++)
{
for (int z = 0; z < 512; z++)
{
++counter;
map[512 * 128 * x + 128 * y + z] = counter;
}
}
}
}
elapsedFill = timer.ElapsedTicks;
Console.WriteLine("Flattened fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[512 * 128 * ordered_values[i].x + 128 * ordered_values[i].y + ordered_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Flattened get all times (ordered): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[512 * 128 * random_values[i].x + 128 * random_values[i].y + random_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Flattened get all times (random): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
}
Thread.Sleep(100);
{ // Jagged
long elapsedAllocation, elapsedFill, elapsedGet, number;
timer.Restart();
int[][][] map = new int[512][][];
for (int y = 0; y < 512; ++y)
{
map[y] = new int[128][];
for (int z = 0; z < 128; ++z)
{
map[y][z] = new int[512];
}
}
elapsedAllocation = timer.ElapsedTicks;
Console.WriteLine("Jagged allocate: {0}ms", Math.Round(elapsedAllocation * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < 20; i++)
{
for (int x = 0; x < 512; x++)
{
for (int y = 0; y < 128; y++)
{
for (int z = 0; z < 512; z++)
{
++counter;
map[x][y][z] = counter;
}
}
}
}
elapsedFill = timer.ElapsedTicks;
Console.WriteLine("Jagged fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[ordered_values[i].x][ordered_values[i].y][ordered_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Jagged get all times (ordered): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
for (int i = 0; i < count_values; ++i)
{
number = map[random_values[i].x][random_values[i].y][random_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Jagged get all times (random): {0}ms", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3));
}
Console.Read();
return 0;
}
}
}
вот вариант с последовательнам и рандомным доступом:
MD
allocate 6
fill 198
get(order) 149
get(rand) 956
FLAT
allocate 0.21
fill 39
get(order) 62.5 \ ??WTF
get(rand) 59.58 / ??WTF
JAGGED
allocate 210
fill 52
get(order) 92
get(rand) 677
|
(Offline)
|
|
29.11.2011, 17:22
|
#50
|
Unity/C# кодер
Регистрация: 03.10.2005
Адрес: Россия, Рязань
Сообщений: 7,568
Написано 3,006 полезных сообщений (для 5,323 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
Мои результаты (i5-2500K 3.3ГГц):
Multidimensional allocate: 4,948ms
Multidimensional fill: 218,264ms
Multidimensional get 65536 times: 0,148ms
Flattened allocate: 0,239ms
Flattened fill: 45,047ms
Flattened get all times (ordered): 60,754ms
Flattened get all times (random): 65,615ms
Jagged allocate: 182,714ms
Jagged fill: 66,86ms
Jagged get all times (ordered): 99,008ms
Jagged get all times (random): 748,584ms
|
(Offline)
|
|
29.11.2011, 17:29
|
#51
|
☭
Регистрация: 26.09.2006
Сообщений: 6,035
Написано 1,474 полезных сообщений (для 2,707 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
вот у тебя тоже наблюдается аномалия на flatten. ordered тоже должен быть быстрее, чем random. но почему то нет. кто сможет объяснить почему?
правка: короче ето из-за оптимизирующего компилятора. вот так:
elapsedFill = timer.ElapsedTicks;
Console.WriteLine("Flattened fill: {0}ms", Math.Round((elapsedFill / 20f) * 1000f / Stopwatch.Frequency, 3));
timer.Restart();
int number1 = 0;
for (int i = 0; i < count_values; ++i)
{
number1 += map[512 * 128 * ordered_values[i].x + 128 * ordered_values[i].y + ordered_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Flattened get all times (ordered): {0}ms number = {1}", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3),number1);
timer.Restart();
number1 = 0;
for (int i = 0; i < count_values; ++i)
{
number1 += map[512 * 128 * random_values[i].x + 128 * random_values[i].y + random_values[i].z];
}
elapsedGet = timer.ElapsedTicks;
Console.WriteLine("Flattened get all times (random): {0}ms number = {1}", Math.Round(elapsedGet * 1000f / Stopwatch.Frequency, 3),number1);
все возвращается на свои места 78 ordered, 533 random.
|
(Offline)
|
|
29.11.2011, 17:38
|
#52
|
☭
Регистрация: 26.09.2006
Сообщений: 6,035
Написано 1,474 полезных сообщений (для 2,707 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
причем на плюсах:
#include <iostream>
#include <Windows.h>
#include <cstdlib>
struct index
{
int x, y, z;
};
int main()
{
int count_values = 512 * 128 * 512;
index *ordered_values = new index[count_values];
index *random_values = new index[count_values];
{
int x = 0, y = 0, z = 0;
for (int i = 0; i < count_values; ++i)
{
ordered_values[i].x = z;
ordered_values[i].y = y;
ordered_values[i].z = x;
x++;
if (x > 511)
{
x = 0;
y++;
}
if (y > 127)
{
y = 0;
z++;
}
random_values[i].x = rand()%512;
random_values[i].y = rand()%128;
random_values[i].z = rand()%512;
}
}
int counter = 0;
auto a = GetTickCount();
int* map = new int[512*128*512];
int allocate_time = GetTickCount() - a;
a = GetTickCount();
for(int i=0;i<20;++i)
{
for(int x =0;x<512;++x)
{
for(int y = 0;y<128;++y)
{
for(int z =0;z<512;++z)
{
++counter;
map[512 * 128 * x + 128 * y + z] = counter;
}
}
}
}
int fill_time = GetTickCount() - a;
a = GetTickCount();
int value = 0;
for(int i=0;i<count_values;++i)
{
value += map[512 * 128 * ordered_values[i].x + 128 * ordered_values[i].y + ordered_values[i].z];
}
int ordered_time = GetTickCount() - a;
std::cout<<"value:"<<value<<std::endl;
a = GetTickCount();
for(int i=0;i<count_values;++i)
{
value += map[512 * 128 * random_values[i].x + 128 * random_values[i].y + random_values[i].z];
}
int random_time = GetTickCount() - a;
std::cout<<"value:"<<value<<std::endl;
std::cout<<"allocate time:"<<allocate_time<<std::endl;
std::cout<<"fill time:"<<(fill_time/20)<<std::endl;
std::cout<<"ordered time:"<<ordered_time<<std::endl;
std::cout<<"random time:"<<random_time<<std::endl;
std::cin.get();
return 0;
}
дает вполне ожидаемые 46 для ordered и 390 для random;
естественно, сюда еще входит время обращение к массиву для получения индекса.
|
(Offline)
|
|
29.11.2011, 18:09
|
#53
|
.
Регистрация: 05.08.2006
Сообщений: 10,429
Написано 3,454 полезных сообщений (для 6,863 пользователей)
|
Что-то я не смог избавиться от "оптимизаций компилятором", которые ухудшили результат получения данных при ordered и random индексах..
UPD: получилось.
Intel Pentium 4 3.00 Ghz
UPD2:
Вот такие результаты:
array size: 512 * 128 * 512 = 33554432
--- Multidimensional
allocate: 25.945ms
fill: 8221.827ms
get Ordered: 6834.768ms
get Random Order: 10833.646ms
--- Flattened
allocate: 39.469ms
fill: 985.824ms
get Ordered: 5357.747ms
get Random Order: 2922.386ms
--- Jagged
allocate: 3119.915ms
fill: 328.575ms
get Ordered: 6037.242ms
get Random Order: 8589.737ms
И вот такие результаты на более малого размера объём:
array size: 256 * 64 * 256 = 4194304
--- Multidimensional
allocate: 2.107ms
fill: 99.551ms
get Ordered: 96.638ms
get Random Order: 401.702ms
--- Flattened
allocate: 0.201ms
fill: 50.118ms
get Ordered: 49.65ms
get Random Order: 281.263ms
--- Jagged
allocate: 39.366ms
fill: 39.935ms
get Ordered: 50.619ms
get Random Order: 390.059ms
Заметьте, что в более малого объёма, как раз есть оптимизация на основе сортировки, а в большом нету..
Это случаем не потому что там идёт какое-то разбиение участка памяти на куски из-за слишком больших размеров?
Вот код обновил:
using System; using System.Diagnostics; using System.Threading;
namespace speedTest { static class Program { public struct index { public int x, y, z; };
static int Main() { long elapsed, number; int width = 256; int height = 64; int depth = 256; int volume = width * height * depth;
Console.WriteLine("array size: {0} * {1} * {2} = {3}", width, height, depth, volume);
index[] indicesOrdered = new index[volume]; index[] indicesRandom = new index[volume];
{ // fill up get values Random rnd = new Random(); int i = 0;
for (int z = 0; z < depth; ++z) { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { indicesOrdered[i].x = z; indicesOrdered[i].y = y; indicesOrdered[i].z = x;
indicesRandom[i].x = rnd.Next(width); indicesRandom[i].y = rnd.Next(height); indicesRandom[i].z = rnd.Next(depth);
++i; } } } }
Stopwatch timer = new Stopwatch();
Console.WriteLine(" --- Multidimensional"); Thread.Sleep(100);
{ // Multidimensional int counter = 0;
timer.Restart();
int[,,] map = new int[width, height, depth];
elapsed = timer.ElapsedTicks; Console.WriteLine("allocate: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { ++counter; map[x, y, z] = counter; } } }
elapsed = timer.ElapsedTicks; Console.WriteLine("fill: \t\t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[indicesOrdered[i].x, indicesOrdered[i].y, indicesOrdered[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Ordered: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[indicesRandom[i].x, indicesRandom[i].y, indicesRandom[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Random Order: \t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); }
Console.WriteLine(" --- Flattened"); Thread.Sleep(100);
{ // Flattened int counter = 0;
timer.Restart();
int[] map = new int[width * height * depth];
elapsed = timer.ElapsedTicks; Console.WriteLine("allocate: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { ++counter; map[width * height * x + height * y + z] = counter; } } }
elapsed = timer.ElapsedTicks; Console.WriteLine("fill: \t\t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[width * height * indicesOrdered[i].x + height * indicesOrdered[i].y + indicesOrdered[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Ordered: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[width * height * indicesRandom[i].x + height * indicesRandom[i].y + indicesRandom[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Random Order: \t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); }
Console.WriteLine(" --- Jagged"); Thread.Sleep(100);
{ // Jagged int counter = 0;
timer.Restart();
int[][][] map = new int[width][][]; for (int y = 0; y < width; ++y) { map[y] = new int[height][];
for (int z = 0; z < height; ++z) { map[y][z] = new int[depth]; } }
elapsed = timer.ElapsedTicks; Console.WriteLine("allocate: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { ++counter; map[x][y][z] = counter; } } }
elapsed = timer.ElapsedTicks; Console.WriteLine("fill: \t\t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[indicesOrdered[i].x][indicesOrdered[i].y][indicesOrdered[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Ordered: \t\t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); timer.Restart();
for (int i = 0; i < volume; ++i) { number = map[indicesRandom[i].x][indicesRandom[i].y][indicesRandom[i].z]; }
elapsed = timer.ElapsedTicks; Console.WriteLine("get Random Order: \t{0}ms", Math.Round(elapsed * 1000f / Stopwatch.Frequency, 3)); } Console.Read(); return 0; } } }
|
(Offline)
|
|
29.11.2011, 18:15
|
#54
|
Unity/C# кодер
Регистрация: 03.10.2005
Адрес: Россия, Рязань
Сообщений: 7,568
Написано 3,006 полезных сообщений (для 5,323 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
Результаты:
array size: 256 * 64 * 256 = 4194304
--- Multidimensional
allocate: 0,743ms
fill: 37,29ms
get Ordered: 16,391ms
get Random Order: 86,846ms
--- Flattened
allocate: 0,073ms
fill: 12,771ms
get Ordered: 13,568ms
get Random Order: 12,551ms
--- Jagged
allocate: 10,595ms
fill: 10,976ms
get Ordered: 12,797ms
get Random Order: 56,314ms
array size: 512 * 128 * 512 = 33554432
--- Multidimensional
allocate: 7,78ms
fill: 258,828ms
get Ordered: 133,145ms
get Random Order: 791,616ms
--- Flattened
allocate: 0,283ms
fill: 55,868ms
get Ordered: 64,609ms
get Random Order: 64,498ms
--- Jagged
allocate: 175,661ms
fill: 86,344ms
get Ordered: 95,213ms
get Random Order: 741,485ms
|
(Offline)
|
|
29.11.2011, 18:38
|
#55
|
.
Регистрация: 05.08.2006
Сообщений: 10,429
Написано 3,454 полезных сообщений (для 6,863 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
Вот ещё потестил, и вывел в виде % кто превосходит или уступает multidimensional массиву, отфильтровав (сверху самые быстрые).
array size: 256 * 64 * 256 = 4194304
alloc:
flat (907%) = 0.201ms
mult (100%) = 1.823ms
jagg (4%) = 42.266ms
fill:
flat (204%) = 50.041ms
jagg (180%) = 56.568ms
mult (100%) = 101.929ms
get ordered:
flat (193%) = 49.872ms
jagg (190%) = 50.646ms
mult (100%) = 96.195ms
get random:
flat (141%) = 275.65ms
mult (100%) = 388.513ms
jagg (99%) = 391.662ms
array size: 512 * 128 * 512 = 33554432
alloc:
flat (1019%) = 1.249ms
mult (100%) = 12.728ms
jagg (2%) = 646.334ms
fill:
jagg (227%) = 333.841ms
flat (192%) = 395.861ms
mult (100%) = 758.735ms
get ordered:
jagg (178%) = 404.737ms
flat (132%) = 544.013ms
mult (100%) = 719.182ms
get random:
flat (118%) = 2809.882ms
mult (100%) = 3304.364ms
jagg (76%) = 4329.8ms
|
(Offline)
|
|
27.09.2012, 00:49
|
#56
|
Дэвелопер
Регистрация: 10.09.2007
Сообщений: 1,442
Написано 793 полезных сообщений (для 1,460 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
вот еще один бенчмарк в копилку. язык F# (для .NET)
постарался товарищ boxxyfag
open System
open Microsoft.FSharp.Collections
let beforeAllocation = DateTime.Now
let yobaArray = Array3D.zeroCreate 512 512 128
let afterAllocation = DateTime.Now
let mutable i = 0
for n in 1..20 do
for x in 0..511 do
for y in 0..511 do
for z in 0..127 do
yobaArray.[x, y, z] <- i
i <- i + 1
let afterLoop = DateTime.Now
let totalLoopTime = afterLoop - afterAllocation
let averageLoopTime = new TimeSpan(totalLoopTime.Ticks / 20L)
printfn "Allocation time: %A" <| afterAllocation - beforeAllocation
printfn "Total loop time: %A" <| totalLoopTime
printfn "Average loop time: %A" <| averageLoopTime
Console.ReadLine() |> ignore
результаты:
Microsoft (R) F# 2.0 Interactive build 4.0.40219.1
Windows 7 Pro 32
Amd turion rm-74 2,20 GHz
Allocation time: 00:00:00.0040002
Total loop time: 00:00:21.1218322
Average loop time: 00:00:01.0560916
|
(Offline)
|
|
27.09.2012, 00:50
|
#57
|
Дэвелопер
Регистрация: 10.09.2007
Сообщений: 1,442
Написано 793 полезных сообщений (для 1,460 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
код на F# с аллокацией и одновременной инициализацией массива:
open System
open Microsoft.FSharp.Collections;
let finalValues =
let arrSize = 512 * 512 * 128
let start = 19 * arrSize
seq { for i in 0..arrSize-1 -> start + i }
let enumerator = finalValues.GetEnumerator()
let getNext _ _ _ =
enumerator.MoveNext()
enumerator.Current
let timeBefore = DateTime.Now
let yobaArray = Array3D.init 512 512 128 getNext
let timeAfter = DateTime.Now
printfn "Allocation and init time: %A" <| timeAfter - timeBefore
Console.ReadLine()
результаты:
Allocation and init time: 00:00:13.5615343
|
(Offline)
|
|
27.09.2012, 00:53
|
#58
|
Дэвелопер
Регистрация: 10.09.2007
Сообщений: 1,442
Написано 793 полезных сообщений (для 1,460 пользователей)
|
Ответ: Великая битва 4х языков программирования на простейшей задачке
код на фортране, который должен по идее был всех победить, но у аффтара с рекордом не вышло
автор: zxc
integer before(3), after(3), I, J, K, N
real loop_time_min, loop_time_sec, avg
dimension A(512, 512, 128)
call itime(before)
! nowN - array for time 1/2/3 -> h/m/s
do 1 N = 1, 20
do 2 I = 1, 512
do 3 J = 1, 512
do 4 K = 1, 512
A(I, J, K) = N
4 continue
3 continue
2 continue
1 continue
CALL itime(after)
loop_time_min = after(2) - before(2)
loop_time_sec = after(3) - before(3)
avg = (loop_time_min*60+loop_time_sec)/20
WRITE(*,*) "Loop Time: ", loop_time_min, loop_time_sec
stop
end
результаты:
Celeron(R) Dual-Core CPU T3500 @ 2.10GHz
Loop Time: 0.0000000 31.000000
AVG: 1.5500000
|
(Offline)
|
|
Сообщение было полезно следующим пользователям:
|
|
Ваши права в разделе
|
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения
HTML код Выкл.
|
|
|
Часовой пояс GMT +4, время: 01:10.
|