Witam.
Moim zamiarem jest wykonanie webservice, który będzie służył do przetwarzania dużych ilości danych. Z tego względu stoję przed wyborem technologii, w której to pisać. Przeprowadziłem mały test na dynamicznej strukturze danych i wygląda na to że Java zupełnie sobie z tym nie radzi.
Jeśli mam gdzieś błąd to proszę o poprawkę.
Kod Java:
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Test {
public static void main(String[] args){
int count = 1000000;
List<Integer> list1 = new ArrayList<Integer>();
Random generator = new Random();
for(int i = 0; i < count; i++) {
list1.add(generator.nextInt());
}
List<Integer> list2 = new ArrayList<Integer>();
for(int i = 0; i < count; i++) {
list2.add(generator.nextInt());
}
long startTime = System.nanoTime();
List<Integer> list3 = new ArrayList<Integer>();
for(int i = 0; i < count; i++) {
list3.add(list2.get(i) + list1.get(i));
}
long endTime = System.nanoTime();
long duration = (endTime - startTime);
double seconds = (double) duration / 1000000000.0;
System.out.println("That took " + seconds + " seconds");
}
}
Wynik:
That took 0.87815511 seconds
Kod C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
int count = 1000000;
List<int> list1 = new List<int>();
Random rand = new Random(count);
for (int i = 0; i < count; i++)
{
list1.Add(rand.Next(count));
}
List<int> list2 = new List<int>();
Random rand2 = new Random(count);
for (int i = 0; i < count; i++)
{
list2.Add(rand2.Next(count));
}
Stopwatch watch = Stopwatch.StartNew();
List<int> list3 = new List<int>();
for (int i = 0; i < count; i++)
{
list3.Add(list1[i] + list2[i]);
}
watch.Stop();
Console.WriteLine("That took {0}ms", watch.ElapsedMilliseconds);
}
}
}
Wynik:
That took 18ms