Skip to content

Instantly share code, notes, and snippets.

@saintedlama
Created September 14, 2010 04:55
Show Gist options
  • Save saintedlama/578567 to your computer and use it in GitHub Desktop.
Save saintedlama/578567 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.DataProviders;
using SubSonic.Repository;
using SubSonic.Tests.Repositories;
using SubSonic.Tests.Repositories.TestBases;
using Xunit;
namespace SubSonic.Tests.Perf
{
public class Projections
{
[Fact]
public void Measure_ProjectionSpeedSetup()
{
var provider = ProviderFactory.GetProvider("Northwind");
provider.Log = Console.Out;
var repo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
// Create some test items
for (var i = 0; i < 1000; i++)
{
var movie = new Movie { Title = "SomeTitle" };
repo.Add(movie);
for (var j = 0; j < 10; j++)
{
var comment = new Comment { Author = "Me", MovieId = movie.Id, Text = "The film is... " };
repo.Add(comment);
}
}
}
[Fact]
public void Measure_ProjectionSpeed()
{
var provider = ProviderFactory.GetProvider("Northwind");
provider.Log = Console.Out;
var repo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
var t1 = DateTime.Now;
var result = (from m in repo.All<Movie>()
from c in repo.All<Comment>()
where m.Id == c.MovieId
select new ProjectionResult { Title = m.Title, Comment = c.Text }).ToString();
var t2 = DateTime.Now;
Console.Out.WriteLine("Time elapsed for selecting and mapping " + (t2 - t1).TotalMilliseconds + " ms");
}
}
public class ProjectionResult
{
public string Title { get; set; }
public string Comment { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment