Replies: 4 comments 5 replies
-
Because
|
Beta Was this translation helpful? Give feedback.
-
Working with Tuple has almost no advantage over List. We also lose benefits such as using linq and other benefits of using Enumrables. |
Beta Was this translation helpful? Give feedback.
-
I created a sample class to test the performance of both methods. The only difference is the clean code, which can be ignored. I will share my code and results with you. thanks.
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
namespace Performance;
internal class PerformanceTester
{
internal static bool Run()
{
using var connection = AppConfig.GetChConn();
var sw = Stopwatch.StartNew();
var tuple_obj = connection.Query<SimpleTuple>("select tuple(number,number,number) Tuples from numbers(10000000)");
var tuple_int = ConvertTuple(tuple_obj.ToArray());
sw.Stop();
Console.WriteLine($"Tuple Time Length: {sw.ElapsedMilliseconds} ms Memory: {GetObjectSize(tuple_obj)} bytes");
sw = Stopwatch.StartNew();
var tuple_arr = connection.Query<SimpleArray>("select array(number ,number ,number) Nums from numbers(10000000)");
sw.Stop();
Console.WriteLine($"Array Time Length: {sw.ElapsedMilliseconds} ms Memory: {GetObjectSize(tuple_arr)} bytes");
return true;
}
private static long GetObjectSize(object o)
{
long size = 0;
using (Stream s = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(s, o);
size = s.Length;
}
return size;
}
private static ulong[][] ConvertTuple(SimpleTuple[] tuple_list)
{
var result = new ulong[tuple_list.Length][];
for (int i = 0; i < tuple_list.Length; i++)
{
result[i] = new ulong[tuple_list[i].Tuples.Length];
for (int j = 0; j < tuple_list[i].Tuples.Length; j++)
{
result[i][j] = (ulong)tuple_list[i].Tuples[j];
}
}
return result;
}
}
[Serializable]
internal class SimpleArray
{
public ulong[] Nums { get; set; }
}
[Serializable]
internal class SimpleTuple
{
public ITuple Tuples { get; set; }
} |
Beta Was this translation helpful? Give feedback.
-
Using substitute types is not clean code, it's an exact opposite. The fact that Dapper does not support You don't actually need an intermediate class
Register it:
And then you can get ITuple out of Dapper trivially:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
Why did you use ITuple class instead of List or IEnumerator?
Beta Was this translation helpful? Give feedback.
All reactions