Created
June 12, 2019 20:16
-
-
Save ayende/d8faf7e9df3d55ee0494de6af085dcf3 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
// install-package ravendb.client | |
// install-package bogus | |
using Raven.Client.Documents; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
namespace Bench.BulkInsert | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var addressGen = new Bogus.Faker<Address>() | |
.StrictMode(true) | |
.RuleFor(x => x.Line1, x => x.Address.StreetAddress()) | |
.RuleFor(x=>x.Line2, x=>x.Random.Int(1, 6) == 3 ? x.Address.SecondaryAddress() : null) | |
.RuleFor(x => x.City, x => x.Address.City()) | |
.RuleFor(x => x.Country, x => x.Address.Country()) | |
.RuleFor(x => x.Zip, x => x.Address.ZipCode()); | |
var userGen = new Bogus.Faker<User>() | |
.StrictMode(true) | |
.Ignore(x=>x.Id) | |
.RuleFor(x => x.Name, x => x.Name.FullName()) | |
.RuleFor(x => x.Email, x => x.Person.Email) | |
.RuleFor(x => x.LastMessage, x => x.Hacker.Phrase()) | |
.RuleFor(x => x.Friends, x => x.Make(x.Random.Number(2,6), () => x.Internet.UserName())) | |
.RuleFor(x => x.Address, x => addressGen.Generate()); | |
using(var store = new DocumentStore | |
{ | |
Database = "bulk", | |
Urls = new [] { "http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com:8080/" } | |
}) | |
{ | |
store.Initialize(); | |
var sp = Stopwatch.StartNew(); | |
using (var bulk = store.BulkInsert()) | |
{ | |
for (int i = 0; i < 100_000; i++) | |
{ | |
var a = userGen.Generate(); | |
bulk.Store(a); | |
} | |
} | |
Console.WriteLine(sp.Elapsed); | |
} | |
} | |
} | |
public class User | |
{ | |
public string Name; | |
public string Id; // generated by RavenDB client | |
public string Email; | |
public Address Address; | |
public List<string> Friends; | |
public string LastMessage; | |
} | |
public class Address | |
{ | |
public string Line1, Line2, City, Country, Zip; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment