File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using FluentAssertions ;
1+ using System ;
2+ using FluentAssertions ;
23using Xunit ;
34
45namespace LiteDbX . Tests . Document ;
@@ -41,4 +42,44 @@ public void ObjectId_Equals_Null_Does_Not_Throw()
4142 oid1 . Equals ( null ) . Should ( ) . BeFalse ( ) ;
4243 oid1 . Equals ( oid0 ) . Should ( ) . BeFalse ( ) ;
4344 }
45+
46+
47+ [ Fact ]
48+ public void ObjectId_ToString_Minimizes_Allocations ( )
49+ {
50+ var objectId = ObjectId . NewObjectId ( ) ;
51+
52+ objectId . ToString ( ) ;
53+
54+ GC . Collect ( ) ;
55+ GC . WaitForPendingFinalizers ( ) ;
56+ GC . Collect ( ) ;
57+
58+ var before = GC . GetAllocatedBytesForCurrentThread ( ) ;
59+ var hex = objectId . ToString ( ) ;
60+ var allocated = GC . GetAllocatedBytesForCurrentThread ( ) - before ;
61+
62+ hex . Should ( ) . HaveLength ( 24 ) ;
63+ allocated . Should ( ) . BeLessThan ( 220 ) ;
64+ }
65+
66+ [ Fact ]
67+ public void ObjectId_FromHex_Minimizes_Allocations ( )
68+ {
69+ var original = ObjectId . NewObjectId ( ) ;
70+ var hex = original . ToString ( ) ;
71+
72+ _ = new ObjectId ( hex ) ;
73+
74+ GC . Collect ( ) ;
75+ GC . WaitForPendingFinalizers ( ) ;
76+ GC . Collect ( ) ;
77+
78+ var before = GC . GetAllocatedBytesForCurrentThread ( ) ;
79+ var parsed = new ObjectId ( hex ) ;
80+ var allocated = GC . GetAllocatedBytesForCurrentThread ( ) - before ;
81+
82+ parsed . Should ( ) . Be ( original ) ;
83+ allocated . Should ( ) . BeLessThan ( 220 ) ;
84+ }
4485}
You can’t perform that action at this time.
0 commit comments