Created
November 4, 2018 05:41
-
-
Save RussellHaley/43d862cb5fb2cd1a1e5e87a14cdebee8 to your computer and use it in GitHub Desktop.
LiteDB Test of 16000 records
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 LiteDB; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace LiteDBTesting | |
{ | |
class Company | |
{ | |
public int Id { get; set; } | |
public string CompanyName { get; set; } | |
public string AddressLine1 { get; set; } | |
public string AddressLine2 { get; set; } | |
public string PostalCode { get; set; } | |
public DateTime Created { get; set; } | |
public List<Invoice> Invoices { get; set; } | |
public Company() | |
{ | |
Invoices = new List<Invoice>(); | |
} | |
public override string ToString() | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.AppendLine(this.CompanyName); | |
sb.AppendLine(this.AddressLine1); | |
sb.AppendLine(this.AddressLine2); | |
sb.AppendLine(this.PostalCode); | |
return sb.ToString(); | |
} | |
} | |
class Invoice | |
{ | |
public DateTime InvoiceDate { get; set; } | |
public List<string> Lines { get; set; } | |
public double Total { get; set; } | |
public Invoice() | |
{ | |
Lines = new List<string>(); | |
} | |
} | |
class Stat | |
{ | |
public int Id { get; set; } | |
public DateTime Timestamp { get; set; } | |
public int Count { get; set; } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
double insertTime = Insert(); | |
int count; | |
using (var db = new LiteDatabase(@"MyData.db")) | |
{ | |
var companies_db = db.GetCollection<Company>("company"); | |
count = companies_db.Count(); | |
} | |
Console.WriteLine("Inserted {0} records in {1} seconds.", count, insertTime); | |
Console.ReadKey(); | |
} | |
static double Insert() | |
{ | |
int NumOfCompanies = 16000; | |
int NumOfInvoices = 10; | |
using (var db = new LiteDatabase(@"MyData.db")) | |
{ | |
Console.WriteLine("Hello World!"); | |
var companies_db = db.GetCollection<Company>("company"); | |
var stats_db = db.GetCollection<Stat>("Statistics"); | |
companies_db.EnsureIndex(i => i.CompanyName, true); | |
DateTime timer = new DateTime(); | |
//companies_db.EnsureIndex(i => i.Invoices., true); | |
Stat stat = new Stat() { Timestamp = DateTime.Now, Count = 0 }; | |
stats_db.Insert(stat); | |
DateTime start = DateTime.Now; | |
timer = DateTime.Now; | |
TimeSpan onesecond = new TimeSpan(0, 0, 1); | |
for (int i = 1; i <= NumOfCompanies; i++) | |
{ | |
if (DateTime.Now - timer > onesecond) | |
{ | |
stat = new Stat() { Timestamp = DateTime.Now, Count = i - stat.Count }; | |
stats_db.Insert(stat); | |
timer = DateTime.Now; | |
//Console.Clear(); | |
//Console.WriteLine(i); | |
} | |
Company c = new Company() | |
{ | |
Id = i, | |
CompanyName = "SmithAndCo-" + i, | |
AddressLine1 = "138" + i + "Ave.", | |
AddressLine2 = "Kelowna BC", | |
PostalCode = "1A2-3B4", | |
Created = DateTime.Now | |
}; | |
for(int j = 0; j < NumOfInvoices; j++) | |
{ | |
Invoice inv = new Invoice() { InvoiceDate = DateTime.Now.AddDays(i) }; | |
inv.Lines.Add("Line 1"); | |
inv.Lines.Add("Line 2"); | |
inv.Total = 100 + ((NumOfCompanies % 3) * NumOfInvoices); | |
c.Invoices.Add(inv); | |
} | |
companies_db.Insert(c); | |
} | |
DateTime finished = DateTime.Now; | |
return (finished - start).TotalSeconds; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment