letmutpig_latin_string=String::with_capacity(english.len()*2);//Plenty of headroom in case the words are very small or the suffixes are long
letmutcurrent_word=String::with_capacity(64);//Longer than all English words to avoid unneeded allocations (plus leaving room for leading and trailing extra characters)
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
letmutstarting_consonants_buffer=String::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
letmutstarting_consonants_buffer=String::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
letmutstarting_consonants_buffer=String::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
letmutstarting_consonants_buffer=String::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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers(
word,
"ay","way","AY","WAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
}
#[bench]
fnyay_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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers(
word,
"ay","yay","AY","YAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
}
#[bench]
fnhay_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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers(
word,
"ay","hay","AY","HAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers(
word,
"erb","ferb","ERB","FERB",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out
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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","way","AY","WAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","yay","AY","YAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers_ascii(
word,
"ay","hay","AY","HAY",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//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
letmutstarting_consonants_buffer=String::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");
translate_word_with_style_reuse_buffers_ascii(
word,
"erb","ferb","ERB","FERB",
&mutpig_latin_word,&mutstarting_consonants_buffer
);
pig_latin_word.truncate(0);
});
eprintln!("{}",pig_latin_word);//To avoid optimizing things out