4 ms·
Unicode of course takes up more space and fills up your buffer sooner. Looks like the jump happens after 8 chars. Benchmark.bm do |bench| run("と", bench
by parfe 15y ago
Unicode of course takes up more space and fills up your buffer sooner. Looks like the jump happens after 8 chars.
Benchmark.bm do |bench|
run("と", bench)
run("がと", bench)
run("りがと", bench)
run("ありがと", bench)
run("ありがとあ", bench)
run("ありがとあり", bench)
run("ありがとありが", bench)
run("ありがとありがと", bench)
run("ありがとありがとあ", bench)
run("ありがとありがとあり", bench)
run("ありがとありがとありと", bench)
run("ありがとありがとありがと", bench)
end
user system total real
2 chars 0.210000 0.000000 0.210000 ( 0.212420)
3 chars 0.200000 0.000000 0.200000 ( 0.199957)
4 chars 0.200000 0.000000 0.200000 ( 0.199356)
5 chars 0.200000 0.000000 0.200000 ( 0.199142)
6 chars 0.200000 0.000000 0.200000 ( 0.198047)
7 chars 0.190000 0.000000 0.190000 ( 0.198984)
8 chars 0.190000 0.000000 0.190000 ( 0.196917)
9 chars 0.250000 0.000000 0.250000 ( 0.245808)
10 chars 0.240000 0.000000 0.240000 ( 0.247153)
11 chars 0.250000 0.000000 0.250000 ( 0.248083)
12 chars 0.250000 0.000000 0.250000 ( 0.247753)
13 chars 0.240000 0.000000 0.240000 ( 0.250674)
Grabbed those unicode chars from http://blog.trydionel.com/2010/03/23/some-unicode-tips-for-ruby/ http://blog.trydionel.com/2010/03/23/some-unicode-tips-for-r... no clue what that says.
- chaosfox 15y agoありがとう -> thanks, note you are missing the う on the end.
- parfe 15y agoYou're welcome. That's what I get for checking up on my limited unicode knowledge before posting, and then just C&Ping. Thanks.
- pat_shaughnessy 15y agoCool! Thanks for taking the time to test this - while the idea of testing with unicode chars occurred to me while writing the post, I didn't have time to get to it...
- microtherion 15y agoYes, hiragana are from an unicode range that encodes to 3 UTF-8 characters each, so ruby appears to use UTF-8. ありがと is "arigato".
- unwind 15y agoYou probably mean "three bytes in UTF-8", talking about "UTF-8 characters" is really confusing.
- microtherion 15y agoYou're absolutely right, I should have said "three bytes" or "three octets".
- Natsu 15y ago> no clue what that says. I think it's supposed to be ありがとう ("arigatou"), which is is Japanese for "thank you" (the informal version). The characters are hiragana. I have no idea why they left off the う at the end, though, except that it just turns the last o into a long o and many foreign speakers are insensitive to the difference between the two because they sound almost the same.
- latchkey 15y agoI also heart google translate. http://translate.google.com/#ja|en|%E3%81%82%E3%82%8A%E3%81%8C%E3%81%A8%E3%81%86 http://translate.google.com/#ja|en|%E3%81%82%E3%82%8A%E3%81%...
- Natsu 15y agoI don't use it. For Japanese, try Rikaichan (a Firefox translation plugin) which lets you look up unfamiliar kanji without leaving the website. You can also look words up on http://www.alc.co.jp/ http://www.alc.co.jp/ but it might be hard to use unless you can read at least basic Japanese.
- ramchip 15y agoIt's pretty common to leave out the う in informal speech.
- aaronblohowiak 15y agoI'm going to split some hairs, because it matters for the topic at hand. >Unicode of course takes up more space and fills up your buffer sooner. Looks like the jump happens after 8 chars. It sounds like you are conflating unicode with UTF-8. There is more than one way to represent the unicode code points, and UTF-8 is one of them. Further, it seems like you assume that "unicode characters" have a constant size. This is a potentially dangerous misunderstanding of how UTF-8 works. UTF-8 code points have a variable number of bytes (from one to four bytes, IIRC.) You happen to have copied some code points that take 3 bytes each. The UTF-8 encoding scheme is a great compromise, and the wikipedia article is easy to follow: http://en.wikipedia.org/wiki/UTF-8 http://en.wikipedia.org/wiki/UTF-8
- NinetyNine 15y agoI also used to believe Unicode and UTF-8 were different types of encoding until someone corrected me. I just remembered why I had thought such a thing in the first place: http://msdn.microsoft.com/en-us/library/system.text.encoding(v=vs.71).aspx http://msdn.microsoft.com/en-us/library/system.text.encoding...
- waterside81 15y agoYou and probably everyone else the first time they encounter unicode / UTF-8. I wonder if it's because both terms start with 'U'.
- deleted 15y ago[deleted]
- parfe 15y agoThanks for correcting my errors.