<div dir="ltr">Your rust version pushes only 10'000'000 strings from arr into str, doesn't it?</div><br><div class="gmail_quote"><div dir="ltr">ср, 13 июл. 2016 г. в 16:41, Branimir Maksimovic <<a href="mailto:branimir.maksimovic@gmail.com">branimir.maksimovic@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<p>rust (no need for array but anyway)</p>
<p>[bmaxa@manjaro rust]$ time ./append<br>
10000000 took 0.064016791<br>
110000000 took 0.13466229<br>
<br>
real 0m0.204s<br>
user 0m0.167s<br>
sys 0m0.033s<br>
</p>
<p>haskell (your fastest version)</p>
<p>[bmaxa@manjaro rust]$ time ./concat <br>
"Done"<br>
<br>
real 0m0.224s<br>
user 0m0.220s<br>
sys 0m0.000s<br>
</p>
<p>c++ (no array)</p>
<p>[bmaxa@manjaro rust]$ time ./a.out <br>
<br>
real 0m0.115s<br>
user 0m0.100s<br>
sys 0m0.013s<br>
</p>
<p>rust:</p>
<p>use std::time::*;<br>
<br>
fn main() {<br>
let mut arr=Vec::new();<br>
arr.reserve(10_000_000);<br>
let start = Instant::now();<br>
for _ in 0 .. 10_000_000 {<br>
arr.push("hello world");<br>
}<br>
let end = start.elapsed();<br>
let diff = (end.as_secs()*1000000000 + end.subsec_nanos() as
u64) as f64/1000000000.;<br>
println!("{} took {}",arr.len(),diff);<br>
let mut str = String::new();<br>
str.reserve(110_000_000);<br>
let start = Instant::now();<br>
for i in arr {<br>
str .push_str(i);<br>
}<br>
let end = start.elapsed();<br>
let diff = (end.as_secs()*1000000000 + end.subsec_nanos() as
u64) as f64/1000000000.;<br>
println!("{} took {}",str.len(),diff);<br>
}<br>
<br>
c++:</p>
<p>#include <stdio.h><br>
#include <string><br>
<br>
<br>
int main() {<br>
std::string tmp;<br>
tmp.reserve(110000000);<br>
for (int i=0;i<10000000;i++) {<br>
tmp += "hello world";<br>
}<br>
}<br>
<br>
Model name: Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz<br>
</p></div><div bgcolor="#FFFFFF" text="#000000">
<br>
<div>On 07/12/2016 05:36 AM, William Yager
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">You picked the single slowest way to do it. Please
see <a href="https://gist.github.com/wyager/df063ad4edd9a9c8b0ab762c91a79894" target="_blank">https://gist.github.com/wyager/df063ad4edd9a9c8b0ab762c91a79894</a>
<div><br>
</div>
<div>All times are on my Intel Atom Macbook. Compiled with -O3,
no other options.</div>
<div><br>
</div>
<div>Using Lazy Bytestrings (either through the Builder
interface or plain old concatenation) is about 7-7.5 times
faster than string concatenation so on your computer it should
take about 0.12 seconds. In other words, faster than C.</div>
<div><br>
</div>
<div>This is my usual experience with lazy bytestrings; due to
their optimization for cache size, they are extremely fast
with almost no effort. They often out-perform "fast" array
operations in C due to fusion and cache coherency. </div>
<div><br>
</div>
<div>I will note that if you want to do exactly what C does
(often with only slightly different assembly output), you can
often achieve this with unboxed vectors (mutable or immutable,
depending on your application).</div>
<div><br>
</div>
<div>--Will<br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Jul 11, 2016 at 10:24 PM,
Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank"><a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a></a>></span>
wrote:
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Making a list of "Hello world" 10,000,000 times and then<br>
concatenating that list to produce a single String took<br>
0.87 seconds (start program to end program) in Haskell.<br>
</blockquote>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
Only members subscribed via the mailman list are allowed to post.</pre>
</blockquote>
<br>
</div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>