Created
May 20, 2016 19:07
-
-
Save bertt/973ec710804186760cdd1b954d06cc7f 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.Diagnostics; | |
using Npgsql; | |
namespace PipeLineDbHelloworld | |
{ | |
class Program | |
{ | |
private static string connString = "Server=192.168.99.100;User Id=pipeline;Password=pipeline;Database=pipeline"; | |
static void Main(string[] args) | |
{ | |
// First create table with continuous view: | |
// CREATE CONTINUOUS VIEW continuous_view AS SELECT x::integer, COUNT(*) FROM stream GROUP BY x | |
var stopWatch=new Stopwatch(); | |
stopWatch.Start(); | |
// stream 100000 records and calculate stats | |
InsertData(); | |
stopWatch.Stop(); | |
// 0.4 seconds... | |
Console.WriteLine("elapsed new school:" + stopWatch.Elapsed.TotalSeconds); | |
/** | |
result: | |
"8"; "10000" | |
"4"; "10000" | |
"1"; "10000" | |
"5"; "10000" | |
"3"; "10000" | |
"0"; "10000" | |
"9"; "10000" | |
"6"; "10000" | |
"2"; "10000" | |
"7"; "10000" | |
*/ | |
Console.ReadKey(); | |
} | |
public static void InsertData() | |
{ | |
var conn = new NpgsqlConnection(connString); | |
conn.Open(); | |
var sql = "COPY stream (x) FROM STDIN"; | |
var importer = conn.BeginTextImport(sql); | |
for (var i = 0; i < 100000; i++) | |
{ | |
// 10 unique groupings | |
var x = i%10; | |
importer.WriteLine(x); | |
} | |
importer.Close(); | |
conn.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment