21 ms·
Why is printing “B” dramatically slower than printing “#”?
- koenigdavidmj 13y agoEntirely unrelated, but this headline made me notice that Chrome finally supports entering " in the find-in-page box and having it match so-called smart quotes.
- shurcooL 13y agoI recall it doing that (for other symbols too) for quite a while. At least 4-6+ months, on stable channel.
- oneeyedpigeon 13y agoYup, it's definitely done that for a while. It does become a pain when you actually want to locate quotes that need smartening up, though.
- GauntletWizard 13y agoWhy? Why would you do that to the world? Smart quotes are about the dumbest concept that has ever existed.
- omaranto 13y agoWhat's so dumb about them? Do you like your opening and closing parenthesis to be the same, too?
- raldi 13y agoNo, which is why they have separate keys on my keyboard, unlike smartquotes, so I can always easily specify exactly which I want. Also nobody magically switches my parentheses around out from under me.
- oneeyedpigeon 13y agoThere are many wonderful characters that don't have their own individual keys on your keyboard. Heck, there are a lot of characters that require at least one meta key to be pressed in combination with another key, and single quote marks are accessible in exactly that way on my keyboard too (Mac, YMMV). And, yes, autocorrect can be a PITA, especially when it's not actually getting things correct, but that's a different, albeit related, issue. We should really refer to quote marks, or apostrophe (which are often rendered as curly, and are the characters that autocorrect switches to), and the prime symbol (which is the unadulterated character that you get with the non-meta-pressed key on your keyboard), rather than using the term 'smart quotes'.
- kps 13y agoNot to detract from the substance of your post, but the unshifted keyboard key pretty much universally generates an ASCII apostrophe (U+0027, '), not a prime (U+2032, ′, as used for feet and minutes, and while I'm babbling, the addition of a second prime for seconds is not a coincidence). ~~~~ wavy lines starting flashback ~~~~ ASCII 1967, in conjunction with its European counterpart ECMA-6, permitted the visual appearance of some characters, including the apostrophe, to be modified so that they could be used as accents when overstruck¹: ' " , ^ ` ~ ˊ ¨ ¸ ˆ ˋ ˉ (using the modern Unicode spacing modifiers) Later versions of ECMA-6 suggested that the accent interpretation be used only when the character was actually overstruck: In the 7-bit character set, some printing symbol may be designed to permit their use for the composition of ac- cented letters when necessary for general interchange of information. A sequence of three characters, comprising a letter, BACKSPACE and one of these symbols, is needed for this composition; the symbol is then regarded as a dia- critical sign. It should be noted that these symbols take on their diacritical significance only when they precede or follow the character BACKSPACE; for example, the symbol corresponding to the code combination 2/7 normally has the significance of APOSTROPHE, but becomes the diacritical sign ACUTE ACCENT when preceded or followed by the character BACKSPACE.² Although this was fine for the printing teletypes in use when ASCII was first designed, early video terminals were too dumb to handle overstrikes, so it never caught on. ¹Revised American Standard Code for Information Interchange, from http://www.wps.com/J/codes/Revised-ASCII/index.html http://www.wps.com/J/codes/Revised-ASCII/index.html ²ECMA-6: 7-Bit coded Character Set, 4th Edition, August 1973, from http://www.ecma-international.org/publications/files/ECMA-ST-WITHDRAWN/ECMA-6,%204th%20Edition,%20August%201973.pdf http://www.ecma-international.org/publications/files/ECMA-ST... ~~~~ wavy lines ending flashback ~~~~
- oneeyedpigeon 13y ago‘Smart quotes’ are actually more typographically ‘correct’; that key on your keyboard is a prime symbol which is NOT the same as an apostrophe or a single quote mark. Apart from reducing ambiguity, they also look a lot nicer (in decent fonts), particularly at larger font sizes. I cringe when I see a prime (or ‘straight quote’) symbol being misused on TV or in print.
- talmand 13y agoJust curious, how do you feel if a font, let's say it is a decent font, is designed to make the apostrophe look like a prime symbol?
- ygra 13y agoGerman Wikipedia uses proper quotes instead of the straight variety. I did a lot of wikignoming a while ago and fixing quotes (and non-breaking spaces, and citation formats) was among the things I did. Being able to quickly find straight quotes on the page is very helpful in that regard.
- w1ntermute 13y agoMeanwhile, Firefox continues to distinguish between e and é when searching, despite Chrome having fixed this bug years ago.
- scott_karana 13y agoDoes it depend on the locale, perhaps?
- reubenmorais 13y ago> this bug "9001 Wrong Things Programmers Assume About Internationalization" This behavior should at a minimum be locale-aware. I would be surprised if Firefox did that by default in my pt-BR profile.
- chavesn 13y ago(I'm not programming this kind of thing so please forgive my ignorance.) Is that loose of a search not actually desirable in "find in page" instances? In other words, are there many words where 'e' matching 'é' would actually generate a false positive? This is the only case I could see that would be problematic. And even then "find in page" is usually used as quick navigation to the minimum matching search (high recall) and not about excluding all possible mismatches (high precision).
- logicchains 13y agoThere are words in other languages, French for instance, that with an accent changed or removed have completely different meaning.
- bausson 13y agoThat is sadly true. It's even worse than that. 'e' is the most used letter in french, but 'é' and 'è' are quite used too. 'ê' and 'ë' being rarer, but still existing. So, I am exaggerating it a bit, but you can compare it to having to search for words with the consonants, because every vowel is considered the same by your search algorithm. Yes, I'm pushing it, but you see the problem it can easily become in huge pages.
- wbsun 13y agoAh, this is off topic and let me close it to show off my power... hmm, are we on SO?
- est 13y agoreminds me of worldwide newbie python Unicode rage. The culprit was Windows's cmd.exe and Linux's LC_ALL
- Ellipsis753 13y agoI find it amazing that they actually got the correct answer. How on earth did they guess that?
- jodrellblank 13y agoThe guesser comments that they have written word-wrap code before many times, and recognised the problem from experience.
- akx 13y agoWhich reaffirms what I've been saying for a while: Plenty of programming prowess is creative pattern matching.
- est 13y ago> How on earth did they guess that? By acting quickly before 5 other power user close the question, of course.
- chavesn 13y agoThat answerer[1] was also one of the close-voters[2]... [1]: http://stackoverflow.com/users/157247/t-j-crowder http://stackoverflow.com/users/157247/t-j-crowder [2]: http://stackoverflow.com/posts/21947452/revisions http://stackoverflow.com/posts/21947452/revisions
- chris_wot 13y agoJust shows that seemingly obscure questions can often show that there are underlying things you need to pay attention to!
- codereflection 13y agoThis post highlights the issue with overly zealous mods on SO who marked the question as off topic. Nothing about this is off topic, and it turned out to be very interesting answer.
- gortok 13y agoThe post was put on hold because the OP failed to provide the information the community would need to reproduce the issue. What good is a programming problem if no one else can reproduce it? To have it reopened, all the OP needs to do is give the community all the information they need to reproduce the issue. Should we ask any less? It's also worth noting that the question was not closed by moderators (denoted by diamonds next to their name), but by members of the community with high reputation (> 3000). These users have community moderation powers by virtue of their reputation, but are not moderators per se. If you have over 3000 reputation, you could vote to reopen. Full disclosure: I am an elected moderator for Stack Overflow: http:stackoverflow.com/users/16587/george-stocker
- RogerL 13y agoAnd yet the community did find the answer.
- deleted 13y ago[deleted]
- overgard 13y agoA) The community did find the answer, regardless. B) Someone is gifting free interesting content to the site; even if it's imperfect does the reaction have to be so harsh? This is, personally, exactly why I never post on stack overflow. You're acting like you're doing them a favor by letting them post there, when they're doing you a favor by giving you interesting content in the first place.
- Manishearth 13y agoB) "Someone is gifting free interesting content to the site". That's the attitude that caused Yahoo! Answers. SE has a higher quality bar, so that there are good, answerable questions. If a question seems unanswerable to many (not due to incompetence but due to incompleteness/clarity/broadness/etc), then it is put on hold. It can be reopened if it gets fixed; putting it on hold lets it get fixed, whilst preventing answers (which might use the wrong interpretation, etc) while it is getting fixed. Saves time for all.
- muro 13y agoPrinting random boobs is slow, okay.
- muro 13y agodid you folks read the code?
- chj 13y agogood detective work!
- tedchs 13y agoApparently the answer had to do with terminal word-wrapping. A good test would be to write the output to a file instead of the terminal and compare the difference in timing.
- VLM 13y agoA graph of wall clock printing speed vs line length for each character would have been highly enlightening. Of course we'd hope anyone who did that would figure it out themselves without posting the question. If it wasn't a line length issue, it probably would have been 1) Proportional kern'd antialiased fonts some glyphs hardware accelerated some not. 2) Maybe for speed it only caches certain font glyphs but its an anti-accelerant strategy this time. After all, what normal person generates outputs like this? 3) UTF-8 to ASCII and or localization code gone wild or similar misoptimization. 4) You'd like to think a simple string printer and the fancy formatted string printer (aka printf and friends) are separate optimized routines but the simple printer might actually be a degenerate form of the formatted printer and the formatted printer has a severe hangup about certain characters. Maybe # is processed quickly but b gets processed extremely slowly because its regex'ing in a very inefficient way to find the \ as in \b. 5) remember LTRS/FIGS from baudot 5 bit teletype coding? Someone trying something "funny" with 3-d accelerated text rendering treating certain letters as 3-d sprites and some not and its getting all messed up and unoptimized this time. Someones LRU cache of 3-d glyph/sprites isn't as LRU as you'd like to think, perhaps.
- fexl 13y agoI bet if he had redirected the output to /dev/null it wouldn't be slower with 'B'.
- cbsmith 13y agoOh good lord. This question is more about properly isolating your tests (i.e. writing the characters to /dev/null and getting rid of the "random" call) and properly profiling code (which would show high CPU consumption on the console, not the program writing to stdout) more than anything "tricky" about performance.
- yeukhon 13y agoThe problem is, who on earth would have thought of printing to terminal would have a big penalty?
- vehementi 13y agoI've run into it before... I've had compiling etc. limited by the speed & size of my console window. Isn't it common knowledge though? Cat some 1GB file to your terminal and notice it takes more than the <100ms it takes to cat it to /dev/null.
- cabinpark 13y agoNever assume something is common knowledge! I've seen many links to mathematics things here on HN that I would consider "common knowledge" yet many people were unaware of them.
- agumonkey 13y agoYou also realize it when adding 'quiet' to the bootloard kernel params. No output => boot time decreased (sometimes halved)
- est 13y ago> who on earth would have thought of Everyone with >5 years of printf() debugging experience.
- zaphar 13y agoI remember minimizing the terminal window to make a script run faster. Taking the text rendering out of the execution path actually had a substantial speedup for long running scripts in some cases. It was one of those things you sort of picked up from other people along the way and assumed everyone knew. Nowadays I don't know if the difference is noticeable enough to be common knowledge though.
- ansible 13y agoThere are terminals that do word wrapping? Well, I shouldn't be surprised... There are people who try to code with a proportional font too, so I guess anything is possible, though it may not make sense to me.
- nolok 13y agoThe output console in many IDE in default configuration, the output console in many linux distros visual updater/installer (eg in xubuntu and mint), etc ... Terminal is a very large word these days. In the SO post, he was using the output console of NetBeans.
- delinka 13y ago1) Asking about running times on code with calls to an RNG ... remove the randomness first, profile repeatedly 2) Outputting to STDOUT can have some serious overhead depending on where you're actually rendering the text-- textview inside your IDE? Crazy, off-the-wall terminals? Let's dump this to a file and see how long it takes
- jrockway 13y agoThis, incidentally, is a good user interface study. The terminal emulator works so well that most users don't even know it's there. But it's actually a pretty complex piece of software.
- gavinpc 13y agoHilarious! I never see confirmation bias in action so much as when SO answers get posted on HN: "See, this is exactly what's wrong with SO." "Really? Because it seems like a perfect example of why SO works perfectly." Of course, I find I am increasingly disposed to read the comments that way...
- prewett 13y agoI'm actually a little surprised that the answer wasn't something along the lines of "# is simple straight lines, while B requires a bunch of Bezier splines for TrueType to render." I guess the graphics cards must accelerate that or something. I'm surprised that line-breaking algorithms take that long.
- agumonkey 13y agoAbout that, I wonder how common are path rendering extensions used ( like NV_PATH http://zrusin.blogspot.fr/2011/09/nv-path-rendering.html http://zrusin.blogspot.fr/2011/09/nv-path-rendering.html ). I'd be sad to hear that my cpu is wasting time on font rendering in 2014.
- GeneralMayhem 13y ago# probably has a decent number of splines in it as well around the corners. It depends on the font, of course, but the Ubuntu font, for example, certainly does.