fighetto
This commit is contained in:
parent
7398654c6a
commit
be678e7cd6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
.criterion
|
.criterion
|
||||||
|
sbocco.sh
|
||||||
|
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -408,6 +408,7 @@ dependencies = [
|
|||||||
"crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -519,6 +520,25 @@ name = "strsim"
|
|||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt-derive"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "0.14.9"
|
version = "0.14.9"
|
||||||
@ -710,6 +730,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d30ec34ac923489285d24688c7a9c0898d16edff27fc1f1bd854edeff6ca3b7f"
|
"checksum serde_json 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d30ec34ac923489285d24688c7a9c0898d16edff27fc1f1bd854edeff6ca3b7f"
|
||||||
"checksum simplelog 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "24b615b1a3cc51ffa565d9a1d0cfcc49fe7d64737ada84eca284cddb0292d125"
|
"checksum simplelog 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "24b615b1a3cc51ffa565d9a1d0cfcc49fe7d64737ada84eca284cddb0292d125"
|
||||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||||
|
"checksum structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e9ad6a11096cbecdcca0cc6aa403fdfdbaeda2fb3323a39c98e6a166a1e45a"
|
||||||
|
"checksum structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4cbce8ccdc62166bd594c14396a3242bf94c337a51dbfa9be1076dd74b3db2af"
|
||||||
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
||||||
"checksum syn 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9056ebe7f2d6a38bc63171816fd1d3430da5a43896de21676dc5c0a4b8274a11"
|
"checksum syn 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9056ebe7f2d6a38bc63171816fd1d3430da5a43896de21676dc5c0a4b8274a11"
|
||||||
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
|
"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7"
|
||||||
|
@ -7,6 +7,7 @@ authors = ["bic <bicno@autistici.org>"]
|
|||||||
crypto-hash = "0.3.1"
|
crypto-hash = "0.3.1"
|
||||||
rayon = "1.0.2"
|
rayon = "1.0.2"
|
||||||
memmap = "0.7.0"
|
memmap = "0.7.0"
|
||||||
|
structopt = "0.2.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.1.2"
|
criterion = "0.1.2"
|
||||||
|
@ -4,10 +4,17 @@ extern crate rainbowcazzi;
|
|||||||
|
|
||||||
use criterion::Criterion;
|
use criterion::Criterion;
|
||||||
use rainbowcazzi::rainbow;
|
use rainbowcazzi::rainbow;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
fn criterion_benchmark(c: &mut Criterion) {
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("sbocco", |b| b.iter(|| rainbow("assets/sbocco")));
|
let infile = File::open("assets/sbocchino").unwrap();
|
||||||
c.bench_function("sbocchino", |b| b.iter(|| rainbow("assets/sbocchino")));
|
c.bench_function("sbocchino", |b| b.iter(|| rainbow(&infile, true)));
|
||||||
|
|
||||||
|
let infile = File::open("assets/sbocco").unwrap();
|
||||||
|
c.bench_function("sbocco", |b| b.iter(|| rainbow(&infile, true)));
|
||||||
|
|
||||||
|
let infile = File::open("assets/sboccone").unwrap();
|
||||||
|
c.bench_function("sbocchino", |b| b.iter(|| rainbow(&infile, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
criterion_group!(benches, criterion_benchmark);
|
criterion_group!(benches, criterion_benchmark);
|
||||||
|
21
src/lib.rs
21
src/lib.rs
@ -1,20 +1,21 @@
|
|||||||
extern crate crypto_hash;
|
extern crate crypto_hash;
|
||||||
extern crate rayon;
|
|
||||||
extern crate memmap;
|
extern crate memmap;
|
||||||
|
extern crate rayon;
|
||||||
|
|
||||||
use crypto_hash::{Algorithm, hex_digest};
|
use crypto_hash::{hex_digest, Algorithm};
|
||||||
use std::fs::File;
|
|
||||||
use memmap::MmapOptions;
|
use memmap::MmapOptions;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
pub fn rainbow(infile: &File, quiet: bool) {
|
||||||
pub fn rainbow(file: &str) {
|
let mmap = unsafe { MmapOptions::new().map(&infile).unwrap() };
|
||||||
let file = File::open(file).unwrap();
|
|
||||||
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
|
|
||||||
|
|
||||||
mmap.par_split(|c| *c == '\n' as u8)
|
mmap.par_split(|c| *c == '\n' as u8)
|
||||||
.map(|coso| {
|
.map(|coso| {
|
||||||
let _hash = hex_digest(Algorithm::MD5, coso);
|
let hash = hex_digest(Algorithm::MD5, coso);
|
||||||
// println!("{}", _hash);
|
if !quiet {
|
||||||
}).collect::<()>();
|
println!("{}", hash);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<()>();
|
||||||
}
|
}
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -1,8 +1,22 @@
|
|||||||
extern crate rainbowcazzi;
|
extern crate rainbowcazzi;
|
||||||
|
extern crate structopt;
|
||||||
|
|
||||||
use rainbowcazzi::rainbow;
|
use rainbowcazzi::rainbow;
|
||||||
|
use std::fs::File;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
fn main() {
|
#[derive(StructOpt, Debug)]
|
||||||
rainbow("assets/sbocco");
|
struct Args {
|
||||||
|
#[structopt(short = "q", long = "quiet")]
|
||||||
|
quiet: bool,
|
||||||
|
#[structopt(name = "input")]
|
||||||
|
input: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = Args::from_args();
|
||||||
|
|
||||||
|
let infile = File::open(args.input).unwrap();
|
||||||
|
|
||||||
|
rainbow(&infile, args.quiet);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user