Worm is thread safety framework therefore you can use cahing mechanisms to improve performance of your application.
Let's slightly modify the program from the previous post.
static void Main(string[] args)
{
DateTime start = DateTime.Now;
for (int i = 0; i < 100; i++)
{
foreach (SalesOrder s in SalesOrder.Query
.Where(Ctor
.prop(typeof(SalesOrder), "OrderDate").eq("2003-08-01")
.and(typeof(SalesOrder), "LineTotal").less_than(10))
.ToList())
{
string str = String.Format("Date: {0}, LineTotal: {1}, sales territory: {2}",
s.OrderDate,
s.LineTotal,
s.Territory.Name);
//Console.WriteLine(str);
}
}
Console.WriteLine("Elapsed {0}", DateTime.Now - start);
}
We added outer loop and calculated the total time. It is 10.7186000 sec on my machine.
Now I'm gonna create cache and use it for database queries.
static void Main(string[] args)
{
ReadonlyCache cache = new ReadonlyCache();
DateTime start = DateTime.Now;
for (int i = 0; i < 100; i++)
{
foreach (SalesOrder s in new QueryCmd(cache, exam1sharp.Properties.Settings.Default.connString)
.From(typeof(SalesOrder))
.Select(typeof(SalesOrder))
.Where(Ctor
.prop(typeof(SalesOrder), "OrderDate").eq("2003-08-01")
.and(typeof(SalesOrder), "LineTotal").less_than(10))
.ToList())
{
string str = String.Format("Date: {0}, LineTotal: {1}, sales territory: {2}",
s.OrderDate,
s.LineTotal,
s.Territory.Name);
//Console.WriteLine(str);
}
}
Console.WriteLine("Elapsed {0}", DateTime.Now - start);
}
As you see, I created ReadonlyCache object and passed it to QueryCmd.
The time is 06.2186704. So we've got 33% performance boost just by changing a couple lines of code. Moreover we've unloaded DBMS from annoying short queries which is very positive fact.