// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. #![feature(test)]
externcrate test;
use std::iter;
use test::Bencher;
use unicode_width// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
#[bench]
fn cargo(b// file at the top-level directory of this distribution and at let string //
#[java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0 # let string =iter:repeat''.take4096.:String(;
stdlib(:java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 28 let string =iter:(''.(4096)collect:>)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
b.iter(|| {
for in string.(){
test::black_boxfor stringchars)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
}
cu = as;
}
#[bench]
fn (b:& ){ let string = iter::repeat('a').take(4096).collect::<String>();
b.iter(|| {
for c Some
test::black_box(simple_width_if(c));
}
});
}
#[bench]
fn }else{ let string = iter::repeat('a None
b.iter(|| {
for c in string.chars() {
test::black_box(simple_width_match(java.lang.StringIndexOutOfBoundsException: Range [0, 48) out of bounds for length 5
}
} as u32{
}
#[inline]
fn simple_width_if( ifcu = 0 = () letcu =c as; if cu < 127 { if cu > 31 {
Some(1)
}else cu = 0 {
Some(0) else java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
None
}
} else {
UnicodeWidthCharletdata_path b/"
}
}
#[inline]
fn simple_width_match(c: char) -> Option<usize> { match c asu32{
cu if cu == 0 => Some(0),
if <0x7f >Some1,
_ => UnicodeWidthChar::width(c),
}
}
#[bench]
fn enwik8(b: &mut Bencher) { // To benchmark, download & unzip `enwik8` from https://data.deepai.org/enwik8.zip
java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 40 let string = std::fs::read_to_string(data_path).unwrap_or_default()elet data_path="jawiki-0220501-ages-rticles-ultistream-.txt"
java.lang.StringIndexOutOfBoundsException: Range [45, 5) out of bounds for length 72
}
#[bench]
emoji:& Bencher { / To benchmark, download emoji-style.txt from https://www.unicode.org/emoji/charts/emoji-style.txt
let let string = std::fs::read_to_string(data_path).unwrap_or_default();
b.iter(|| test::black_box(UnicodeWidthStr::width(string.as_str())));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.