Jeudi 14 Aout 2008
Les bizarreries de .NET
J'avais besoin de quelques informations sur les performances de .NET au niveau de l'accès aux types de données primitifs, donc j'ai réalisé ce petit test, et les résultats sont assez étrange:

Avant NGEN:
******** StructBenchmark v1.0 
Release Build 
Running with no debugger attached 
CLR Version: 2.0.50727.1433 
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 3 
Processor Count: 1 
**** Local variable Tests 
 * Int32 variable increments (1000000000): 1687ms 
 * Int16 variable increments (1000000000): 1031ms 
 * UInt8 variable increments (1000000000): 1554ms 
**** LayoutKind.Auto Tests (Local variable) 
 * Int32 field increments (1000000000): 3652ms 
 * Int16 field increments (1000000000): 3369ms 
 * UInt8 field increments (1000000000): 4336ms 
**** LayoutKind.Explicit Tests (Local variable) 
 * Int32 field increments (1000000000): 2981ms 
 * Int16 field increments (1000000000): 3618ms 
 * UInt8 field increments (1000000000): 4490ms 
**** LayoutKind.Auto Tests (Member variable) 
 * Int32 field increments (1000000000): 2689ms 
 * Int16 field increments (1000000000): 2668ms 
 * UInt8 field increments (1000000000): 2605ms 
**** LayoutKind.Explicit Tests (Member variable) 
 * Int32 field increments (1000000000): 2651ms 
 * Int16 field increments (1000000000): 6191ms 
 * UInt8 field increments (1000000000): 6120ms

Après NGEN:
******** StructBenchmark v1.0 
Release Build 
Running with no debugger attached 
CLR Version: 2.0.50727.1433 
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 3 
Processor Count: 1 
**** Local variable Tests 
 * Int32 variable increments (1000000000): 1736ms 
 * Int16 variable increments (1000000000): 1031ms 
 * UInt8 variable increments (1000000000): 1028ms 
**** LayoutKind.Auto Tests (Local variable) 
 * Int32 field increments (1000000000): 2987ms 
 * Int16 field increments (1000000000): 4472ms 
 * UInt8 field increments (1000000000): 3364ms 
**** LayoutKind.Explicit Tests (Local variable) 
 * Int32 field increments (1000000000): 3613ms 
 * Int16 field increments (1000000000): 4461ms 
 * UInt8 field increments (1000000000): 3353ms 
**** LayoutKind.Auto Tests (Member variable) 
 * Int32 field increments (1000000000): 4117ms 
 * Int16 field increments (1000000000): 3617ms 
 * UInt8 field increments (1000000000): 2268ms 
**** LayoutKind.Explicit Tests (Member variable) 
 * Int32 field increments (1000000000): 3298ms 
 * Int16 field increments (1000000000): 6175ms 
 * UInt8 field increments (1000000000): 6169ms

Malheureusement je ne peux pas regarder le code x86 généré (flemme d'installer tout Visual Studio pour ça :p ), mais les résultats sont assez étranges ^^

Je fournis le code source et les binaires pour ceux qui voudraient tester: StructBenchmark.7z
Inutile de préciser que ça devrait tourner sans problèmes avec Mono pour les curieux. (Si ce n'est pas le cas il suffira de me le dire je regarderai)
Posté à
20:32
 par GoldenCrystal - | Programmation

2. squalyl à 13:20 20/08/2008 -
tiens j'ai fait a peu près la même chose en java:

Java native type benchmark, 1.000.000.000 increments
==========================
Java version: 1.6.0_06
OS name: Windows XP
OS version: 5.1

Local atoms
* long : 1844 ms
* int : 1453 ms
* short : 1453 ms
* byte : 1500 ms

Static member atoms
* long : 3500 ms
* int : 2375 ms
* short : 2891 ms
* byte : 2906 ms

Local object
* long : 2391 ms
* int : 2531 ms
* short : 2531 ms
* byte : 2547 ms

Member object
* long : 2906 ms
* int : 2344 ms
* short : 2547 ms
* byte : 2562 ms
==========================
done.

1. squalyl à 11:55 20/08/2008 -
je sais pas ce que c'est ngen mais:

******** StructBenchmark v1.0
Release Build
Running with no debugger attached
CLR Version: 2.0.50727.42
Operating System: Microsoft Windows NT 5.1.2600 Service Pack 2
Processor Count: 1
**** Local variable Tests
* Int32 variable increments (1000000000): 543ms
* Int16 variable increments (1000000000): 563ms
* UInt8 variable increments (1000000000): 543ms
**** LayoutKind.Auto Tests (Local variable)
* Int32 field increments (1000000000): 1816ms
* Int16 field increments (1000000000): 2539ms
* UInt8 field increments (1000000000): 2212ms
**** LayoutKind.Explicit Tests (Local variable)
* Int32 field increments (1000000000): 1842ms
* Int16 field increments (1000000000): 2551ms
* UInt8 field increments (1000000000): 2312ms
**** LayoutKind.Auto Tests (Member variable)
* Int32 field increments (1000000000): 2603ms
* Int16 field increments (1000000000): 2601ms
* UInt8 field increments (1000000000): 2558ms
**** LayoutKind.Explicit Tests (Member variable)
* Int32 field increments (1000000000): 2566ms
* Int16 field increments (1000000000): 16349ms
* UInt8 field increments (1000000000): 16366ms

vachement long, à la fin.

Pseudo :

Adresse mail : (optionnel)

Site web : (optionnel)

Veuillez entrer la somme de deux et huit :
Message :


 RSS  - ©yNBlogs 2004