Elem idemo dalje, bolji rezultat za Haskell se dobija sa -A50m, tj 50 mega za start arenu.
Code:
~/…/d/bible >>> time ./bbl4 +RTS -N -A50m -s
63924 the
51696 and
34734 of
13561 to
12913 that
12667 in
10420 he
9838 shall
8997 unto
8971 for
8854 i
8473 his
8177 a
7830 lord
7376 they
7013 be
6989 is
6659 him
6596 not
6430 them
327,384,584 bytes allocated in the heap
164,768 bytes copied during GC
242,856 bytes maximum residency (1 sample(s))
158,552 bytes maximum slop
0 MB total memory in use (0 MB lost due to fragmentation)
[CODE] Tot time (elapsed) Avg pause Max pause
Gen 0 0 colls, 0 par 0.000s 0.000s 0.0000s 0.0000s
Gen 1 1 colls, 0 par 0.002s 0.002s 0.0015s 0.0015s
TASKS: 34 (1 bound, 33 peak workers (33 total), using -N16)
SPARKS: 0(0 converted, 0 overflowed, 0 dud, 0 GC’d, 0 fizzled)
INIT time 0.014s ( 0.036s elapsed)
MUT time 0.508s ( 0.310s elapsed)
GC time 0.002s ( 0.002s elapsed)
EXIT time 0.002s ( 0.004s elapsed)
Total time 0.526s ( 0.352s elapsed)
Alloc rate 644,731,727 bytes per MUT second
Productivity 96.6% of total user, 88.2% of total elapsed
./bbl4 +RTS -N -A50m -s 0.39s user 0.15s system 146% cpu 0.370 total
[/CODE]
A sad i Rust. Moj omiljeni jezik, koji isto pratim od pocetka
MT resenje podestite CONC na kolko imate logickih procesora:
Code:
use std::fs::File;
use std::io;
use std::io::prelude::;
use std::collections::;
use std::sync::mpsc;
use std::thread;
static CONC:usize = 16;
fn main()->Result<(),std::io::Error> {
let mut buf : String = String::new();
let mut file = File::open(“bible.txt”)?;
let n = file.read_to_string(&mut buf)?;
let filtered =
buf.chars().filter(|c| !is_punct(*c)).collect::()
.to_lowercase();
let filtered:Vec = filtered.split_whitespace().map(|x| x.to_string()).collect();
let mut hm : HashMap<String,u32> = HashMap::new();
let chunks = chunks(CONC,&filtered);
let clen = chunks.len();
[CODE]let (tx, rx) = mpsc::channel();
for i in chunks {
let tx = tx.clone();
thread::spawn(move || {
let mut hm: HashMap<String,u32> = HashMap::new();
for j in i {
let v = hm.entry(j).or_insert(0);
*v += 1;
}
tx.send(hm).unwrap();
});
}
for _ in 0..clen {
let lst = rx.recv().unwrap();
for (k,v) in lst {
let vv = hm.entry(k).or_insert(0);
*vv += v;
}
}
let mut bm:Vec<(u32,String)> = Vec::new();
for (i,j) in hm {
bm.push((j,i));
}
bm.sort();
let mut k = 1;
for (i,j) in bm.iter().rev().take(20) {
println!("{:2} {:8} {}",k,i,j);
k+=1;
}
Ok(())
}
fn chunks<T:Clone>(n: usize,mut buf : &[T])->Vec<Vec> {
let mut res = Vec::new();
let clen = buf.len() / n;
while buf.len() > clen {
let chunk:Vec = buf[…clen].to_vec();
buf = &buf[clen…];
res.push(chunk)
}
if buf.len() > 0 {
let chunk:Vec = buf.to_vec();
res.push(chunk);
}
res
}
fn is_punct(c: char)->bool{
c == ‘’’ || c == ‘.’ || c == ‘;’ || c == ‘(’ || c == ‘)’
|| c == ‘"’ || c == ‘?’ || c == ‘-’ || c == ‘_’ || c == ‘!’
|| c == ‘,’ || c == ‘:’ || c == ‘|’
}
[/CODE]
Iskompajlirajte sa:
rustc -O -C target-cpu=native bbl.rs
rezultat:
~/.../d/bible >>> time ./bbl 1 63924 the 2 51696 and 3 34734 of 4 13561 to 5 12913 that 6 12667 in 7 10420 he 8 9838 shall 9 8997 unto 10 8971 for 11 8854 i 12 8473 his 13 8177 a 14 7830 lord 15 7376 they 16 7013 be 17 6989 is 18 6659 him 19 6596 not 20 6430 them ./bbl 0.46s user 0.05s system 157% cpu 0.326 total