Created
May 21, 2017 17:37
-
-
Save ElemarJR/0b6167dbe192532da563d9e3c4b68737 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Linq; | |
using Raven.Client; | |
using Raven.Client.Document; | |
using Raven.Client.Indexes; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var index = new Orders_ByOrderedAt(); | |
index.Execute(DocumentStoreHolder.Store); | |
Console.Title = "Timings demo"; | |
using (var session = DocumentStoreHolder.Store.OpenSession()) | |
{ | |
RavenQueryStatistics stats; | |
//var query = session.Query<Order, Orders_ByOrderedAt>() | |
var query = session.Query<Order>() | |
.Statistics(out stats) | |
.Customize(q => q.ShowTimings()); | |
var orders = ( | |
from order in query | |
orderby order.OrderedAt | |
select order | |
) | |
.ToList(); | |
Console.WriteLine(stats.IndexName); | |
var detailedInfo = stats.TimingsInMilliseconds; | |
Console.WriteLine($"Orders count : {orders.Count}"); | |
Console.WriteLine($"Total results: {stats.TotalResults}"); | |
Console.WriteLine(""); | |
Console.WriteLine($"Time (ms) \t Element"); | |
foreach (var entry in detailedInfo) | |
{ | |
Console.WriteLine($"{entry.Value} \t\t {entry.Key} "); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} | |
public static class DocumentStoreHolder | |
{ | |
private static readonly Lazy<IDocumentStore> LazyStore = | |
new Lazy<IDocumentStore>(() => | |
{ | |
var store = new DocumentStore | |
{ | |
Url = "http://localhost:8080", | |
DefaultDatabase = "Northwind" | |
}; | |
store.Initialize(); | |
return store; | |
}); | |
public static IDocumentStore Store => | |
LazyStore.Value; | |
} | |
public class Order | |
{ | |
public string Id { get; set; } | |
public string Company { get; set; } | |
public DateTimeOffset OrderedAt { get; set; } | |
} | |
public class Orders_ByOrderedAt : AbstractIndexCreationTask<Order> | |
{ | |
public Orders_ByOrderedAt() | |
{ | |
Map = orders => | |
from order in orders | |
select new | |
{ | |
order.OrderedAt | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment