Discussion:
[rust-dev] Timing vector inserts
Fredrik Widlund
2014-09-25 19:17:42 UTC
Permalink
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/

(disclaimer: *not* about comparing languages and claiming language X is
"better" than language Y)

Kind regards,
Fredrik Widlund
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/401687ba/attachment.html>
Clark Gaebel
2014-09-25 19:33:03 UTC
Permalink
I sent a pull request, but the tl;dr of it is that the rust version was run without optimizations turned on.

On Thu, Sep 25, 2014 at 12:17 PM, Fredrik Widlund
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
(disclaimer: *not* about comparing languages and claiming language X is
"better" than language Y)
Kind regards,
Fredrik Widlund
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/2b76d094/attachment.html>
Fredrik Widlund
2014-09-25 19:37:47 UTC
Permalink
Great, thanks! Will update asap.

F
Post by Clark Gaebel
I sent a pull request, but the tl;dr of it is that the rust version was
run without optimizations turned on.
On Thu, Sep 25, 2014 at 12:17 PM, Fredrik Widlund <
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
(disclaimer: *not* about comparing languages and claiming language X is
"better" than language Y)
Kind regards,
Fredrik Widlund
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/27e1fc6f/attachment.html>
Daniel Micay
2014-09-25 22:59:48 UTC
Permalink
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
(disclaimer: *not* about comparing languages and claiming language X is
"better" than language Y)
Kind regards,
Fredrik Widlund
https://github.com/jemalloc/jemalloc/issues/126

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/0e0d16ac/attachment.sig>
Clark Gaebel
2014-09-25 23:05:38 UTC
Permalink
You?re also timing two pushes, as opposed to a push and an array write in the C version.

On Thu, Sep 25, 2014 at 3:59 PM, Daniel Micay <danielmicay at gmail.com>
Post by Daniel Micay
Post by Fredrik Widlund
http://lonewolfer.wordpress.com/2014/09/24/benchmarking-dynamic-array-implementations/
(disclaimer: *not* about comparing languages and claiming language X is
"better" than language Y)
Kind regards,
Fredrik Widlund
https://github.com/jemalloc/jemalloc/issues/126
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/2be2a2bb/attachment.html>
François-Xavier Bourlet
2014-09-26 01:18:59 UTC
Permalink
On my machine I get:

C: 100000000,0.509391
rust: 100000000,0.466069

So rust is faster for me.

For fun, I tried to write the rust version using unsafe and
pre-allocation to remove the second push:

let mut m = Vec::from_fn(101, |_| 0);
let pm = m.as_mut_ptr();
let mut m_idx = 1i;
let t = time::precise_time_ns();
for _i in iter::range_step(0, n, n/100) {
for j in range(0, n/100) {
v.push(j);
}
unsafe {
ptr::write(pm.offset(m_idx as int), time::precise_time_ns() - t);
}
m_idx += 1;
}

But I get a little slower result (maybe I am doing something wrong
with the unsafe and ptr):
rust2: 100000000,0.472749

And just to be sure, I tested getting rid of iterators (using manual
while loop instead) and this changed nothing (as expected).

my 2 cents
Post by Clark Gaebel
You?re also timing two pushes, as opposed to a push and an array write in the C version.
<signature.asc>
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
François-Xavier Bourlet
2014-09-26 01:26:56 UTC
Permalink
and hitting reply-all is better...

quick update: the implementation with unsafe & ptr is not slower. I
just have too many cores + power-boost to get a clean benchmark every
time.
Running the benchs with n=1 billions (instead of 100 millions) gives me:


==> vector_grow_c.csv <==
1000000000,5.084604

==> vector_grow_rust.csv <==
1000000000,5.217096

==> vector_grow_rust2.csv <==
1000000000,4.912147 (yes, getting rid of the second push works!)

$ rustc --version
rustc 0.12.0-pre-nightly (0e784e168 2014-09-16 23:26:11 +0000)
$ gcc --version
gcc (GCC) 4.9.1

On Thu, Sep 25, 2014 at 6:18 PM, Fran?ois-Xavier Bourlet
Post by François-Xavier Bourlet
C: 100000000,0.509391
rust: 100000000,0.466069
So rust is faster for me.
For fun, I tried to write the rust version using unsafe and
let mut m = Vec::from_fn(101, |_| 0);
let pm = m.as_mut_ptr();
let mut m_idx = 1i;
let t = time::precise_time_ns();
for _i in iter::range_step(0, n, n/100) {
for j in range(0, n/100) {
v.push(j);
}
unsafe {
ptr::write(pm.offset(m_idx as int), time::precise_time_ns() - t);
}
m_idx += 1;
}
But I get a little slower result (maybe I am doing something wrong
rust2: 100000000,0.472749
And just to be sure, I tested getting rid of iterators (using manual
while loop instead) and this changed nothing (as expected).
my 2 cents
Post by Clark Gaebel
You?re also timing two pushes, as opposed to a push and an array write in the C version.
<signature.asc>
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
Clark Gaebel
2014-09-26 04:30:50 UTC
Permalink
Another problem I noticed is that the elements in the vector in the rust code are `uint` (which on most systems is 64-bit) and in the C code you?re inserting `int`s (32-bits on most systems).




That?s not really a fair contest.




? - Clark

On Thu, Sep 25, 2014 at 6:26 PM, Fran?ois-Xavier Bourlet
Post by François-Xavier Bourlet
and hitting reply-all is better...
quick update: the implementation with unsafe & ptr is not slower. I
just have too many cores + power-boost to get a clean benchmark every
time.
==> vector_grow_c.csv <==
1000000000,5.084604
==> vector_grow_rust.csv <==
1000000000,5.217096
==> vector_grow_rust2.csv <==
1000000000,4.912147 (yes, getting rid of the second push works!)
$ rustc --version
rustc 0.12.0-pre-nightly (0e784e168 2014-09-16 23:26:11 +0000)
$ gcc --version
gcc (GCC) 4.9.1
On Thu, Sep 25, 2014 at 6:18 PM, Fran?ois-Xavier Bourlet
Post by François-Xavier Bourlet
C: 100000000,0.509391
rust: 100000000,0.466069
So rust is faster for me.
For fun, I tried to write the rust version using unsafe and
let mut m = Vec::from_fn(101, |_| 0);
let pm = m.as_mut_ptr();
let mut m_idx = 1i;
let t = time::precise_time_ns();
for _i in iter::range_step(0, n, n/100) {
for j in range(0, n/100) {
v.push(j);
}
unsafe {
ptr::write(pm.offset(m_idx as int), time::precise_time_ns() - t);
}
m_idx += 1;
}
But I get a little slower result (maybe I am doing something wrong
rust2: 100000000,0.472749
And just to be sure, I tested getting rid of iterators (using manual
while loop instead) and this changed nothing (as expected).
my 2 cents
Post by Clark Gaebel
You?re also timing two pushes, as opposed to a push and an array write in
the C version.
<signature.asc>
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140925/f6de48ee/attachment.html>
François-Xavier Bourlet
2014-09-26 19:21:02 UTC
Permalink
with i32 for rust:
(I am on x86_64)

==> vector_grow_c.csv <==
1000000000,4.741286

==> vector_grow_rust.csv <==
1000000000,3.147506

==> vector_grow_rust2.csv <==
1000000000,3.153482
Post by Clark Gaebel
Another problem I noticed is that the elements in the vector in the rust
code are `uint` (which on most systems is 64-bit) and in the C code you?re
inserting `int`s (32-bits on most systems).
That?s not really a fair contest.
- Clark
On Thu, Sep 25, 2014 at 6:26 PM, Fran?ois-Xavier Bourlet <bombela at gmail.com>
Post by François-Xavier Bourlet
and hitting reply-all is better...
quick update: the implementation with unsafe & ptr is not slower. I
just have too many cores + power-boost to get a clean benchmark every
time.
==> vector_grow_c.csv <==
1000000000,5.084604
==> vector_grow_rust.csv <==
1000000000,5.217096
==> vector_grow_rust2.csv <==
1000000000,4.912147 (yes, getting rid of the second push works!)
$ rustc --version
rustc 0.12.0-pre-nightly (0e784e168 2014-09-16 23:26:11 +0000)
$ gcc --version
gcc (GCC) 4.9.1
On Thu, Sep 25, 2014 at 6:18 PM, Fran?ois-Xavier Bourlet
Post by François-Xavier Bourlet
C: 100000000,0.509391
rust: 100000000,0.466069
So rust is faster for me.
For fun, I tried to write the rust version using unsafe and
let mut m = Vec::from_fn(101, |_| 0);
let pm = m.as_mut_ptr();
let mut m_idx = 1i;
let t = time::precise_time_ns();
for _i in iter::range_step(0, n, n/100) {
for j in range(0, n/100) {
v.push(j);
}
unsafe {
ptr::write(pm.offset(m_idx as int), time::precise_time_ns() - t);
}
m_idx += 1;
}
But I get a little slower result (maybe I am doing something wrong
rust2: 100000000,0.472749
And just to be sure, I tested getting rid of iterators (using manual
while loop instead) and this changed nothing (as expected).
my 2 cents
Post by Clark Gaebel
You?re also timing two pushes, as opposed to a push and an array write in
the C version.
<signature.asc>
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
Fredrik Widlund
2014-09-27 10:44:56 UTC
Permalink
Hi,

The benchmarks are updated since a while back, all versions use 64 bit
values, and there are different versions for jemalloc and the glibc
allocator (for Rust and C).

As noted by Daniel Micay the most important factor here will be the memory
allocator. Rust builds with jemalloc by default, which compared to the
glibc allocator on my Linux system is about twice as slow. Without knowing
anything about your system a likely cause could be that the allocator used
for the C version on your system is not the glibc allocator.

The timing operation is run every 1/10^6 iteration (or 1/10^7 in your
case), so optimizing it should not typically change the result.

F


On Fri, Sep 26, 2014 at 9:21 PM, Fran?ois-Xavier Bourlet <bombela at gmail.com>
Post by François-Xavier Bourlet
(I am on x86_64)
==> vector_grow_c.csv <==
1000000000,4.741286
==> vector_grow_rust.csv <==
1000000000,3.147506
==> vector_grow_rust2.csv <==
1000000000,3.153482
Post by Clark Gaebel
Another problem I noticed is that the elements in the vector in the rust
code are `uint` (which on most systems is 64-bit) and in the C code
you?re
Post by Clark Gaebel
inserting `int`s (32-bits on most systems).
That?s not really a fair contest.
- Clark
On Thu, Sep 25, 2014 at 6:26 PM, Fran?ois-Xavier Bourlet <
bombela at gmail.com>
Post by Clark Gaebel
Post by François-Xavier Bourlet
and hitting reply-all is better...
quick update: the implementation with unsafe & ptr is not slower. I
just have too many cores + power-boost to get a clean benchmark every
time.
==> vector_grow_c.csv <==
1000000000,5.084604
==> vector_grow_rust.csv <==
1000000000,5.217096
==> vector_grow_rust2.csv <==
1000000000,4.912147 (yes, getting rid of the second push works!)
$ rustc --version
rustc 0.12.0-pre-nightly (0e784e168 2014-09-16 23:26:11 +0000)
$ gcc --version
gcc (GCC) 4.9.1
On Thu, Sep 25, 2014 at 6:18 PM, Fran?ois-Xavier Bourlet
Post by François-Xavier Bourlet
C: 100000000,0.509391
rust: 100000000,0.466069
So rust is faster for me.
For fun, I tried to write the rust version using unsafe and
let mut m = Vec::from_fn(101, |_| 0);
let pm = m.as_mut_ptr();
let mut m_idx = 1i;
let t = time::precise_time_ns();
for _i in iter::range_step(0, n, n/100) {
for j in range(0, n/100) {
v.push(j);
}
unsafe {
ptr::write(pm.offset(m_idx as int), time::precise_time_ns() - t);
}
m_idx += 1;
}
But I get a little slower result (maybe I am doing something wrong
rust2: 100000000,0.472749
And just to be sure, I tested getting rid of iterators (using manual
while loop instead) and this changed nothing (as expected).
my 2 cents
Post by Clark Gaebel
You?re also timing two pushes, as opposed to a push and an array
write
Post by Clark Gaebel
Post by François-Xavier Bourlet
Post by François-Xavier Bourlet
Post by Clark Gaebel
in
the C version.
On Thu, Sep 25, 2014 at 3:59 PM, Daniel Micay <danielmicay at gmail.com
<signature.asc>
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
Rust-dev at mozilla.org
https://mail.mozilla.org/listinfo/rust-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140927/50e86625/attachment.html>
Loading...