letmutpig_latin_word=String::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutpig_latin_word=Vec::<u8>::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutstarting_consonants_buffer=Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
letmutpig_latin_word=String::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutpig_latin_word=Vec::<u8>::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutstarting_consonants_buffer=Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
b.iter(||{
letword=test::black_box("translator");
letword=test::black_box(b"translator");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","way","AY","WAY",
b"ay",b"way",b"AY",b"WAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
eprintln!("{}",std::str::from_utf8(pig_latin_word.as_slice()).unwrap());//To avoid optimizing things out
}
#[bench]
fnascii_yay_the_word_translator(b: &mutBencher){
letmutpig_latin_word=String::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutpig_latin_word=Vec::<u8>::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutstarting_consonants_buffer=Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
b.iter(||{
letword=test::black_box("translator");
letword=test::black_box(b"translator");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","yay","AY","YAY",
b"ay",b"yay",b"AY",b"YAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
eprintln!("{}",std::str::from_utf8(pig_latin_word.as_slice()).unwrap());//To avoid optimizing things out
}
#[bench]
fnascii_hay_the_word_translator(b: &mutBencher){
letmutpig_latin_word=String::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutpig_latin_word=Vec::<u8>::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutstarting_consonants_buffer=Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
b.iter(||{
letword=test::black_box("translator");
letword=test::black_box(b"translator");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","hay","AY","HAY",
b"ay",b"hay",b"AY",b"HAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
eprintln!("{}",std::str::from_utf8(pig_latin_word.as_slice()).unwrap());//To avoid optimizing things out
}
#[bench]
fnascii_ferb_the_word_translator(b: &mutBencher){
letmutpig_latin_word=String::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutpig_latin_word=Vec::<u8>::with_capacity(64*2);//Longer than all English words to avoid unneeded allocations, times 2 to leave room for whitespace, symbols, and the suffix
letmutstarting_consonants_buffer=Vec::<u8>::with_capacity(64);//Longer than basically all English words to avoid unneeded allocations, plus the fact that this isn't the whole word
b.iter(||{
letword=test::black_box("translator");
letword=test::black_box(b"translator");
translate_word_with_style_reuse_buffers_ascii(
word,
"erb","ferb","ERB","FERB",
b"erb",b"ferb",b"ERB",b"FERB",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
eprintln!("{}",std::str::from_utf8(pig_latin_word.as_slice()).unwrap());//To avoid optimizing things out