Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Increase the #[inline] opportunities - 15-40% performance improvements#100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Manishearth merged 3 commits intounicode-rs:masterfromtimClicks:inline-functions
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionCargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ no_std = [] # This is a no-op, preserved for backward compatibility only.

[dev-dependencies]
quickcheck = "0.7"
bencher = "0.1"
criterion = "0.3"

[[bench]]
name = "graphemes"
Expand Down
59 changes: 29 additions & 30 deletionsbenches/graphemes.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
#[macro_use]
extern crate bencher;
extern crate unicode_segmentation;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use unicode_segmentation;

use bencher::Bencher;
use unicode_segmentation::UnicodeSegmentation;
use std::fs;
use unicode_segmentation::UnicodeSegmentation;

fn graphemes(bench: &mutBencher, path: &str) {
fn graphemes(c: &mutCriterion, lang: &str, path: &str) {
let text = fs::read_to_string(path).unwrap();
bench.iter(|| {
for g in UnicodeSegmentation::graphemes(&*text, true) {
bencher::black_box(g);
}
});

bench.bytes = text.len() as u64;
c.bench_function(&format!("graphemes_{}",lang), |bench| {
bench.iter(|| {
for g in UnicodeSegmentation::graphemes(black_box(&*text), true) {
black_box(g);
}
})
});
}

fn graphemes_arabic(bench: &mutBencher) {
graphemes(bench,"benches/texts/arabic.txt");
fn graphemes_arabic(c: &mutCriterion) {
graphemes(c, "arabic" ,"benches/texts/arabic.txt");
}

fn graphemes_english(bench: &mutBencher) {
graphemes(bench,"benches/texts/english.txt");
fn graphemes_english(c: &mutCriterion) {
graphemes(c, "english" ,"benches/texts/english.txt");
}

fn graphemes_hindi(bench: &mutBencher) {
graphemes(bench,"benches/texts/hindi.txt");
fn graphemes_hindi(c: &mutCriterion) {
graphemes(c, "hindi" ,"benches/texts/hindi.txt");
}

fn graphemes_japanese(bench: &mutBencher) {
graphemes(bench,"benches/texts/japanese.txt");
fn graphemes_japanese(c: &mutCriterion) {
graphemes(c, "japanese" ,"benches/texts/japanese.txt");
}

fn graphemes_korean(bench: &mutBencher) {
graphemes(bench,"benches/texts/korean.txt");
fn graphemes_korean(c: &mutCriterion) {
graphemes(c, "korean" ,"benches/texts/korean.txt");
}

fn graphemes_mandarin(bench: &mutBencher) {
graphemes(bench,"benches/texts/mandarin.txt");
fn graphemes_mandarin(c: &mutCriterion) {
graphemes(c, "mandarin" ,"benches/texts/mandarin.txt");
}

fn graphemes_russian(bench: &mutBencher) {
graphemes(bench,"benches/texts/russian.txt");
fn graphemes_russian(c: &mutCriterion) {
graphemes(c, "russian" ,"benches/texts/russian.txt");
}

fn graphemes_source_code(bench: &mutBencher) {
graphemes(bench,"benches/texts/source_code.txt");
fn graphemes_source_code(c: &mutCriterion) {
graphemes(c, "source_code","benches/texts/source_code.txt");
}

benchmark_group!(
criterion_group!(
benches,
graphemes_arabic,
graphemes_english,
Expand All@@ -61,4 +60,4 @@ benchmark_group!(
graphemes_source_code,
);

benchmark_main!(benches);
criterion_main!(benches);
8 changes: 8 additions & 0 deletionssrc/grapheme.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -228,6 +228,7 @@ enum PairResult {
Emoji, // a break if preceded by emoji base and (Extend)*
}

#[inline]
fn check_pair(before: GraphemeCat, after: GraphemeCat) -> PairResult {
use crate::tables::grapheme::GraphemeCat::*;
use self::PairResult::*;
Expand DownExpand Up@@ -407,6 +408,7 @@ impl GraphemeCursor {
}
}

#[inline]
fn decide(&mut self, is_break: bool) {
self.state = if is_break {
GraphemeState::Break
Expand All@@ -415,11 +417,13 @@ impl GraphemeCursor {
};
}

#[inline]
fn decision(&mut self, is_break: bool) -> Result<bool, GraphemeIncomplete> {
self.decide(is_break);
Ok(is_break)
}

#[inline]
fn is_boundary_result(&self) -> Result<bool, GraphemeIncomplete> {
if self.state == GraphemeState::Break {
Ok(true)
Expand All@@ -432,6 +436,7 @@ impl GraphemeCursor {
}
}

#[inline]
fn handle_regional(&mut self, chunk: &str, chunk_start: usize) {
use crate::tables::grapheme as gr;
let mut ris_count = self.ris_count.unwrap_or(0);
Expand All@@ -452,6 +457,7 @@ impl GraphemeCursor {
self.state = GraphemeState::Regional;
}

#[inline]
fn handle_emoji(&mut self, chunk: &str, chunk_start: usize) {
use crate::tables::grapheme as gr;
let mut iter = chunk.chars().rev();
Expand DownExpand Up@@ -482,6 +488,7 @@ impl GraphemeCursor {
self.state = GraphemeState::Emoji;
}

#[inline]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this should probably go below the docs

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks. I thought I saw this pattern somewhere else in the crate and decided to follow. Will submit a follow-up PR that moves all of them below the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

sounds good!

/// Determine whether the current cursor location is a grapheme cluster boundary.
/// Only a part of the string need be supplied. If `chunk_start` is nonzero or
/// the length of `chunk` is not equal to `len` on creation, then this method
Expand DownExpand Up@@ -563,6 +570,7 @@ impl GraphemeCursor {
}
}

#[inline]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

same

/// Find the next boundary after the current cursor position. Only a part of
/// the string need be supplied. If the chunk is incomplete, then this
/// method might return `GraphemeIncomplete::PreContext` or
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp