forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c787b4d
commit 183e05f
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.NH3141 | ||
{ | ||
public class Entity | ||
{ | ||
public virtual int Id { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/NHibernate.Test/NHSpecificTest/NH3141/Mappings.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" | ||
assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.NH3141"> | ||
<class name="Entity"> | ||
<id name="Id" type="int"> | ||
<generator class="native"/> | ||
</id> | ||
</class> | ||
</hibernate-mapping> | ||
|
63 changes: 63 additions & 0 deletions
63
src/NHibernate.Test/NHSpecificTest/NH3141/ProxyIdPerformanceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3141 | ||
{ | ||
[TestFixture] | ||
public class ProxyIdPerformanceTest : BugTestCase | ||
{ | ||
private int id; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
id = (int) s.Save(new Entity()); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var s = OpenSession()) | ||
using (var tx = s.BeginTransaction()) | ||
{ | ||
s.CreateQuery("delete from Entity e").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test, Explicit("No logical test - just to compare before/after fix")] | ||
public void ShouldUseIdDirectlyFromProxy() | ||
{ | ||
var proxyEntity = CreateInitializedProxy(); | ||
|
||
const int loop = 1000000; | ||
var watch = new Stopwatch(); | ||
watch.Start(); | ||
const int dummyValue = 0; | ||
for (var i = 0; i < loop; i++) | ||
{ | ||
dummyValue.CompareTo(proxyEntity.Id); | ||
} | ||
watch.Stop(); | ||
|
||
//before fix: 2.2s | ||
//after fix: 0.8s | ||
Console.WriteLine(watch.Elapsed); | ||
} | ||
|
||
private Entity CreateInitializedProxy() | ||
{ | ||
using (var s = OpenSession()) | ||
using (s.BeginTransaction()) | ||
{ | ||
var proxyEntity = s.Load<Entity>(id); | ||
NHibernateUtil.Initialize(proxyEntity); | ||
return proxyEntity; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters