Commit 0ff34d2d authored by Yuanle Song's avatar Yuanle Song
Browse files

add benchmark on rust

parent b9aa4cdd
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
* COMMENT -*- mode: org -*-
#+Date: 2016-12-16
Time-stamp: <2016-12-17>
Time-stamp: <2016-12-23>

* database binding benchmark
I want to know the efficiency of the db binding for different language,
@@ -17,6 +17,9 @@ libraries and database servers.
  UPDATE foo SET bar=bar+1 WHERE id=1

* benchmark results
each entry has format: db_server, compiler, libraries
all build is release mode (with -O or equivalent).

** postgres 9.4, cpython 2.7, psycopg2==2.6.1
http://initd.org/psycopg/docs/usage.html
0.35
@@ -57,3 +60,12 @@ https://www.postgresql.org/docs/9.4/static/libpq.html
--
0.63
26.6
** postgres 9.4, rust 1.13.0, postgres 0.13
0.48
26.3
--
0.53
26.2
--
0.50
28.0
+1 −0
Original line number Diff line number Diff line
target
+135 −0
Original line number Diff line number Diff line
[root]
name = "bench"
version = "0.1.0"
dependencies = [
 "postgres 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "bufstream"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "fallible-iterator"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "hex"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "libc"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "log"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "md5"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "phf"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "phf_shared"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "postgres"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bufstream 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "fallible-iterator 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)",
 "postgres-protocol 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "postgres-protocol"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "fallible-iterator 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "md5 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "time"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum bufstream 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b48dbe2ff0e98fa2f03377d204a9637d3c9816cd431bfe05a8abbd0ea11d074"
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
"checksum fallible-iterator 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d48ab1bc11a086628e8cc0cc2c2dc200b884ac05c4b48fb71d6036b6999ff1d"
"checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum md5 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7df230903ccdffd6b3b4ec21624498ea64c912ce50297846907f0b8e1bb249dd"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0c6afb2057bb5f846a7b75703f90bc1cef4970c35209f712925db7768e999202"
"checksum phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "286385a0e50d4147bce15b2c19f0cf84c395b0e061aaf840898a7bf664c2cfb7"
"checksum postgres 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)" = "484a6e73fea94103030d284b71d70182fd804d3e18026b43869f8b1e2b766a56"
"checksum postgres-protocol 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283e27d237a5772ef00c9e3f97e632f9a565ff514761af3e88e129576af7077c"
"checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
+8 −0
Original line number Diff line number Diff line
[package]
name = "bench"
version = "0.1.0"
authors = ["Yuanle Song <sylecn@gmail.com>"]

[dependencies]
postgres = "0.13"
time = "0.1"
+48 −0
Original line number Diff line number Diff line
extern crate postgres;
extern crate time;

use postgres::{Connection, TlsMode};
use postgres::params::{UserInfo, ConnectParams, ConnectTarget};
use time::PreciseTime;

const TIMES: i32 = 3000;

fn select_test(conn: &Connection) {
    for _ in 0..TIMES {
        conn.query("SELECT id, bar FROM foo", &[]).unwrap();
    }
}

fn update_test(conn: &Connection) {
    for _ in 0..TIMES {
        conn.execute("UPDATE foo SET bar=bar+1 WHERE id=1", &[]).unwrap();
    }
}

fn main() {
    let params = ConnectParams {
        target: ConnectTarget::Tcp(String::from("localhost")),
        port: None,
        user: Some(UserInfo {
            user: "t1".to_owned(),
            password: Some(String::from("fNfwREMqO69TB9YqE+/OzF5/k+s="))
        }),
        database: Some(String::from("t1")),
        options: vec![],
    };
    let conn = Connection::connect(params, TlsMode::None).unwrap();
    for row in &conn.query("SELECT id, bar FROM foo", &[]).unwrap() {
        let id_: i32 = row.get("id");
        let bar: i32 = row.get("bar");
        println!("id={} bar={}", id_, bar);
    }
    let start = PreciseTime::now();
    select_test(&conn);
    let end = PreciseTime::now();
    println!("{}", start.to(end));

    let start = PreciseTime::now();
    update_test(&conn);
    let end = PreciseTime::now();
    println!("{}", start.to(end));
}