Hydrating Objects With Expression Trees - Part III
To finalize this series on object hydration, I’ll show some performance comparisons between the different methods of hydrating objects.
For the purpose of this exercise, I’ll use this class:
class SomeType
{
public int Id { get; set; }
public string Name { get; set; }
public DateTimeOffset CreationTime { get; set; }
public Guid UniqueId { get; set; }
}
and this set of data:
var data = (
from i in Enumerable.Range(1, ObjectCount)
select new object[] { i, i.ToString(), DateTimeOffset.Now, Guid.NewGuid() }
).ToArray();
The data bellow shows the time (in seconds) for different runs for different values of ObjectCount (in the same machine with approximately the same load) as well as it’s availability for different version of the .NET Framework and the C# programming language:
|
<td colspan="3" align="center">10000</td>
<td colspan="3" align="center">100000</td>
<td colspan="3" align="center">1000000</td>
<td colspan="2" align="center">Valid for</td>
</tr>
<tr>
<td align="center">Setup</td>
<td align="center">Hydrate</td>
<td align="center">Total</td>
<td align="center">Setup</td>
<td align="center">Hydrate</td>
<td align="center">Total</td>
<td align="center">Setup</td>
<td align="center">Hydrate</td>
<td align="center">Total</td>
<td align="center">Framework version</td>
<td align="center">C# Version</td>
</tr>
<tr>
<td align="left">Activation and Reflection setter</td>
<td align="right">0.060</td>
<td align="right">0.101</td>
<td align="right">0.161</td>
<td align="right">0.055</td>
<td align="right">0.736</td>
<td align="right">0.791</td>
<td align="right">0.054</td>
<td align="right">6.822</td>
<td align="right">6.876</td>
<td align="center">1.0, 1.1, 2.0, 3.5, 4.0</td>
<td align="center">1.0, 2.0, 3.0, 4.0</td>
</tr>
<tr>
<td align="left"><a title="Hydrating Objects With Expression Trees - Part I" href="http://paulomorgado.net/en/blog/archive/2010/08/16/hydrating-objects-with-expression-trees-part-i.aspx" target="_blank">Activation and Expression Tree setter</a></td>
<td align="right">0.300</td>
<td align="right">0.003</td>
<td align="right">0.303</td>
<td align="right">0.313</td>
<td align="right">0.049</td>
<td align="right">0.359</td>
<td align="right">0.293</td>
<td align="right">0.578</td>
<td align="right">0.871</td>
<td align="center">4.0</td>
<td align="center">none</td>
</tr>
<tr>
<td align="left"><a title="Hydrating Objects With Expression Trees - Part II" href="http://paulomorgado.net/en/blog/archive/2010/08/16/hydrating-objects-with-expression-trees-part-ii.aspx" target="_blank">Member Initializer</a></td>
<td align="right">0.035</td>
<td align="right">0.001</td>
<td align="right">0.036</td>
<td align="right">0.039</td>
<td align="right">0.027</td>
<td align="right">0.066</td>
<td align="right">0.041</td>
<td align="right">0.518</td>
<td align="right">0.559</td>
<td align="center">3.5, 4.0</td>
<td align="center">3.0, 4.0</td>
</tr>
</tbody></table>
These values will vary with the number of the objects being hydrated and the number of its properties, but the method using the Member Initializer will be the most performant.
Code samples for this series of posts (and the one about object dumping with expression trees) can be found on my MSDN Code Gallery: Dump And Hydrate Objects With Expression Trees