|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 07:11 | ||
| Оценка: |
-1
|
||
using System;
using System.Collections;
using System.Runtime;
namespace Hashtablebenchmark
{
class Program
{
static void Main(string[] args)
{
int n = 10000000;
for (int j=0; j<10; ++j) {
var startTime = DateTime.Now;
Hashtable hashtable = new Hashtable(n);
for (int i = 1; i <= n; ++i)
hashtable.Add(i, 1.0f / i);
Console.WriteLine("m[100] = " + hashtable[100]);
var endTime = DateTime.Now;
var time = endTime- startTime;
Console.WriteLine("Took: " + time.TotalMilliseconds / 1e3 + "s");
}
Console.ReadKey();
}
}
}<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<gcConcurrent enabled="false"/>
<gcServer enabled="true" />
</runtime>
</configuration>package hashtablebenchmark;
import java.util.HashMap;
public class Hashtablebenchmark {
public static void main(String[] args) {
int n = 10000000;
for (int j=0; j<10; ++j) {
long startTime = System.currentTimeMillis();
HashMap hashtable = new HashMap(n);
for(int i=1; i<=n; ++i)
hashtable.put(i, 1.0f / i);
System.out.println("m[100] = " + hashtable.get(100));
long time = System.currentTimeMillis() - startTime;
System.out.println("Took: " + time / 1e3 + "s");
}
}
}|
|
От: |
tofox2
|
|
| Дата: | 30.06.15 07:41 | ||
| Оценка: | |||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 07:48 | ||
| Оценка: | |||
|
|
От: | Somescout | |
| Дата: | 30.06.15 07:50 | ||
| Оценка: | 2 (1) +4 | ||
Hashtable hashtable = new Hashtable(n);| Результат | |
| m[100] = 0,01 Took: 2,2621291s m[100] = 0,01 Took: 2,1791195s m[100] = 0,01 Took: 2,2051228s m[100] = 0,01 Took: 2,2191271s m[100] = 0,01 Took: 2,2661294s m[100] = 0,01 Took: 2,0771193s m[100] = 0,01 Took: 2,1621237s m[100] = 0,01 Took: 1,9841147s m[100] = 0,01 Took: 2,4391384s m[100] = 0,01 Took: 2,2581295s | |
var hashtable = new System.Collections.Generic.Dictionary<int, double>(n);| Результат | |
| m[100] = 0,01 Took: 0,1880258s m[100] = 0,01 Took: 0,2429998s m[100] = 0,01 Took: 0,2470129s m[100] = 0,01 Took: 0,2510149s m[100] = 0,01 Took: 0,249014s m[100] = 0,01 Took: 0,2530143s m[100] = 0,01 Took: 0,2550155s m[100] = 0,01 Took: 0,2510141s m[100] = 0,01 Took: 0,2500144s m[100] = 0,01 Took: 0,2510148s | |
|
|
От: | Somescout | |
| Дата: | 30.06.15 08:11 | ||
| Оценка: | |||
C:\Temp>java hashtablebenchmark.Hashtablebenchmark -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC -XX:+AggressiveOpts
m[100] = 0.01
Took: 15.03s
m[100] = 0.01
Took: 14.831s
m[100] = 0.01
Took: 10.032s
m[100] = 0.01
Took: 6.485s
m[100] = 0.01
Took: 7.296s
m[100] = 0.01
Took: 6.138s
m[100] = 0.01
Took: 7.199s
m[100] = 0.01
Took: 8.847s
m[100] = 0.01
Took: 3.847s
m[100] = 0.01
Took: 5.502s|
|
От: | Jack128 | |
| Дата: | 30.06.15 08:27 | ||
| Оценка: | |||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 08:44 | ||
| Оценка: | |||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 08:57 | ||
| Оценка: |
-2
|
||
var hashtable = new System.Collections.Generic.Dictionary<int, double>(n);|
|
От: | Somescout | |
| Дата: | 30.06.15 08:57 | ||
| Оценка: | |||
C:\Temp>"c:\Program Files\Java\jre8\bin\java.exe" hashtablebenchmark.Hashtablebenchmark -Xmx3550m -Xms3550m -Xmn2g -Xss128k
-XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC -XX:+AggressiveOpts -server
m[100] = 0.01
Took: 14.763s
m[100] = 0.01
Took: 15.381s
m[100] = 0.01
Took: 13.893s
m[100] = 0.01
Took: 11.663s
m[100] = 0.01
Took: 8.053s
m[100] = 0.01
Took: 7.803s
m[100] = 0.01
Took: 7.746s
m[100] = 0.01
Took: 4.668s
m[100] = 0.01
Took: 3.827s
m[100] = 0.01
Took: 4.049s
C:\Temp>"c:\Program Files\Java\jre8\bin\java.exe" -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)c:\Temp>"c:\Program Files\Java\jre1.8.0_45\bin\java.exe" hashtablebenchmark.Hashtablebenchmark -Xmx3550m -Xms3550m -Xmn
2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC -XX:+AggressiveOpts -server
m[100] = 0.01
Took: 9.318s
m[100] = 0.01
Took: 3.293s
m[100] = 0.01
Took: 6.128s
m[100] = 0.01
Took: 7.477s
m[100] = 0.01
Took: 0.734s
m[100] = 0.01
Took: 0.39s
m[100] = 0.01
Took: 0.641s
m[100] = 0.01
Took: 2.588s
m[100] = 0.01
Took: 3.285s
m[100] = 0.01
Took: 2.617s
c:\Temp>"c:\Program Files\Java\jre1.8.0_45\bin\java.exe" -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
|
|
От: |
Ночной Смотрящий
|
|
| Дата: | 30.06.15 09:14 | ||
| Оценка: | +2 | ||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 09:26 | ||
| Оценка: | |||
Hashtable is thread safe for use by multiple reader threads and a single writing thread. It is thread safe for multi-thread use when only one of the threads perform write (update) operations, which allows for lock-free reads provided that the writers are serialized to the Hashtable.
A Dictionary can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. In the rare case where an enumeration contends with write accesses, the collection must be locked during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
|
|
От: | Yoriсk | |
| Дата: | 30.06.15 09:56 | ||
| Оценка: | +4 | ||
M>A Dictionary can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. In the rare case where an enumeration contends with write accesses, the collection must be locked during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.
If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally.
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 10:07 | ||
| Оценка: | -1 | ||
|
|
От: |
Ночной Смотрящий
|
|
| Дата: | 30.06.15 10:13 | ||
| Оценка: | +1 -1 | ||
|
|
От: |
Ночной Смотрящий
|
|
| Дата: | 30.06.15 10:13 | ||
| Оценка: | |||
|
|
От: |
Ночной Смотрящий
|
|
| Дата: | 30.06.15 10:21 | ||
| Оценка: | |||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 10:22 | ||
| Оценка: | -1 | ||
|
|
От: |
mapnik
|
http://www.hooli.xyz/ |
| Дата: | 30.06.15 10:32 | ||
| Оценка: | -1 | ||
|
|
От: |
Sharov
|
|
| Дата: | 30.06.15 10:33 | ||
| Оценка: | |||
|
|
От: | Yoriсk | |
| Дата: | 30.06.15 10:57 | ||
| Оценка: | |||