[Haskell-cafe] Is the #functional programming paradigm antithetical to efficient strings? #Haskell

Geraldus heraldhoi at gmail.com
Thu Jul 14 04:42:09 UTC 2016


Your rust version pushes only 10'000'000 strings from arr into str, doesn't
it?

ср, 13 июл. 2016 г. в 16:41, Branimir Maksimovic <
branimir.maksimovic at gmail.com>:

> rust (no need for array but anyway)
>
> [bmaxa at manjaro rust]$ time ./append
> 10000000 took 0.064016791
> 110000000 took 0.13466229
>
> real    0m0.204s
> user    0m0.167s
> sys    0m0.033s
>
> haskell (your fastest version)
>
> [bmaxa at manjaro rust]$ time ./concat
> "Done"
>
> real    0m0.224s
> user    0m0.220s
> sys    0m0.000s
>
> c++ (no array)
>
> [bmaxa at manjaro rust]$ time ./a.out
>
> real    0m0.115s
> user    0m0.100s
> sys    0m0.013s
>
> rust:
>
> use std::time::*;
>
> fn main() {
>     let mut arr=Vec::new();
>     arr.reserve(10_000_000);
>     let start = Instant::now();
>     for _ in 0 .. 10_000_000 {
>         arr.push("hello world");
>     }
>     let end = start.elapsed();
>     let diff = (end.as_secs()*1000000000 + end.subsec_nanos() as u64) as
> f64/1000000000.;
>     println!("{} took {}",arr.len(),diff);
>     let mut str = String::new();
>     str.reserve(110_000_000);
>     let start = Instant::now();
>     for i in arr {
>         str .push_str(i);
>     }
>     let end = start.elapsed();
>     let diff = (end.as_secs()*1000000000 + end.subsec_nanos() as u64) as
> f64/1000000000.;
>     println!("{} took {}",str.len(),diff);
> }
>
> c++:
>
> #include <stdio.h>
> #include <string>
>
>
> int main() {
>     std::string tmp;
>     tmp.reserve(110000000);
>     for (int i=0;i<10000000;i++) {
>         tmp += "hello world";
>     }
> }
>
> Model name:            Intel(R) Core(TM) i3-5005U CPU @ 2.00GHz
>
> On 07/12/2016 05:36 AM, William Yager wrote:
>
> You picked the single slowest way to do it. Please see
> https://gist.github.com/wyager/df063ad4edd9a9c8b0ab762c91a79894
>
> All times are on my Intel Atom Macbook. Compiled with -O3, no other
> options.
>
> 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.
>
> 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.
>
> 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).
>
> --Will
>
> On Mon, Jul 11, 2016 at 10:24 PM, Richard A. O'Keefe <ok at cs.otago.ac.nz>
> wrote:
>>
>>
>> Making a list of "Hello world" 10,000,000 times and then
>> concatenating that list to produce a single String took
>> 0.87 seconds (start program to end program) in Haskell.
>>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160714/1a567e70/attachment.html>


More information about the Haskell-Cafe mailing list