[HN Gopher] Do you know how much your computer can do in a secon...
___________________________________________________________________
Do you know how much your computer can do in a second? (2015)
Author : surprisetalk
Score : 87 points
Date : 2023-06-22 18:27 UTC (4 hours ago)
(HTM) web link (computers-are-fast.github.io)
(TXT) w3m dump (computers-are-fast.github.io)
| sublinear wrote:
| Why are so many of these written in python? That seems against
| the spirit of this quiz. Should change the name of the site to
| "how fast is python really?"
| yen223 wrote:
| I presume it's because Python has a reputation for being a slow
| language, and this quiz wanted to show that even "slow" Python
| code can be fast on modern hardware, unless you touch IO.
|
| That, and Python is probably the most accessible language for
| the most number of people.
| 7speter wrote:
| I imagine it might be because python is a much easier to read
| language. If someone with a non programming background comes
| across this because the question (and answer) is interesting to
| them, they can have an idea of whats going on.
| weatherlight wrote:
| I don't find python easier or harder to, compared to..ruby,
| javascript, ( or even OCaml) for example.
|
| Most people who are tech adjacent, learn declarative langs
| like SQL, HTML first. Python doesn't look like that at all.
|
| It's like when people say "Go is so easy to read!" I learned
| to program in SML then OCaml, __insert other FP langs__ then
| Ruby and ES6, Go looked pretty alien to me the first time I
| saw it.
| jangxx wrote:
| That's cool and all, but then you're not "most people".
| Personally I found Go super easy to read the first time I
| saw it, but my journey through the programming languages
| was also a different one.
| herpderperator wrote:
| I think there's a bug after completing the first question. After
| I selected an answer for how many iterations of an empty loop
| Python could do, it said the answer was incorrect and showed that
| 68 million was the correct answer, but proceeded to explain that
| Python can do 68k iterations in an empty loop. This means the
| answer shown and the explanation are contradictory and likely one
| of them is wrong, probably the explanation.
|
| Edit: Apparently I forgot to account for the milliseconds part.
| My bad.
| ladberg wrote:
| The 68k is per _millisecond_ , which lines up with 68M per
| second.
| nathanwh wrote:
| "68,000 iterations of an empty loop in a millisecond" The
| factor of 1000 comes from the conversion from seconds in the
| question, to milliseconds in the blurb.
| globular-toast wrote:
| Most of this is not really "computers are fast" but rather
| "algorithms are cool". That's fine, of course.
| roninkoi wrote:
| What surprised me the most is how fast grepping is. It can search
| more bytes from memory than iterations in a simple for loop?
| burntsushi wrote:
| It provided the easiest possible case to grep: a simple
| literal. So all grep needs to do is substring search. And in
| turn it's accelerated by use of memchr. And that in turn it's
| written in assembly using AVX2 vector instructions, courtesy of
| GNU libc.
| taldo wrote:
| Probably a pretty bad test of the _actual_ speed of grep. A
| more realistic test would have printable characters and
| frequent newlines. I wouldn't be surprised if all those bytes
| were just taking a fast-path shortcut somewhere.
| dan-robertson wrote:
| Grep _is_ fast. Like obviously in this case you're 'just'
| measuring how fast you can read from a pipe, but there are
| plenty of ways grep could have been implemented that would
| have been slower. Generally, I think grep will convert
| queries into a form that can be searched for reasonably
| efficiently (eg KMP for longer strings (bit of a guess - not
| sure how good it is on modern hardware), obviously no
| backtracking for regular expressions.
| burntsushi wrote:
| I don't think KMP has been used in any practical substring
| implementation in ages. At least I'm not aware of one. I
| believe GNU grep uses Boyer-Moore, but that's not really
| the key here. The key is using memchr in BM's skip loop.
| SnowflakeOnIce wrote:
| Depending on many factors (like details of the patterns used
| and the input), some regex engines (like Hyperscan) can match
| tens of gigabytes per second per core. Shockingly fast!
| Night_Thastus wrote:
| Especially ripgrep! All hail ripgrep!
|
| I will never go back to not using it.
| mud_dauber wrote:
| I toured my eventual college's CS dept as a HS senior (this was a
| LONG time ago. Punch cards, people.)
|
| One machine counted clock cycles between two key presses using
| the same finger. From what I recall the smallest answers were in
| the ... thousands?
| jamestimmins wrote:
| This is awesome. It was fun to see where my intuition was way
| off. Had no idea indexing/not-indexing a column would make a
| 25,000x difference (makes sense though as logN on a 10-million
| row table is 13, which is a lot less than a linear scan).
|
| Was also very surprised to see how slow Bcrypt is.
|
| _edit:_ Yes, BCrypt, is designed to be slow. I just had no idea
| how slow. I assumed it was 100-1000 times faster than it is /can
| be.
| TonyTrapp wrote:
| > Was also very surprised to see how slow Bcrypt is.
|
| Though unlike all the other examples here, this one is actually
| intentional. If/when computers become considerably faster, the
| cost factor of typical bcrypt implementations will be raised so
| that it _stays_ slow, to keep it difficult to throw brute-force
| attacks at it.
| jamestimmins wrote:
| For sure, that's an important piece. But when I hear "slow
| hashing" I assumed it meant 1k-10k times per second, not <10
| times per second. That's practically human speed.
| stavros wrote:
| The bcrypt example is the only one that's off the mark. "How
| fast is this function that we've explicitly designed to be
| arbitrarily slow?" Well, it depends, how slowly did you
| configure it to run?
|
| Basically the important argument to bcrypt is literally the
| amount of time you want it to take to run on your hardware (ie
| the number of rounds).
| ilyt wrote:
| Load half a webpage sadly...
|
| The only thing I learned is apparently default Python JSON lib
| sucks on speed
| deepspace wrote:
| Or displaying 1/2 a character in the Visual Studio editor.
| dan-robertson wrote:
| 50MB/s was my guess for a json parser written in a direct way
| in a moderately fast language that doesn't read into some
| optimised representation (eg I assume the python one constructs
| python data structures). The json file is 64k (which may have
| been what threw you off) so that comes to ~750 per second. But
| my guess of 50MB/a could be way off (might be imagining a
| slower implementation but then the computer for the tests is
| also a bit slow, I think)
| tmtvl wrote:
| The test computer may be a little slow-ish but it doesn't
| seem "commodity laptop picked up from local supermarket"
| slow. It has an SSD, for example.
| JohnFen wrote:
| I can grasp it about as well as I can grasp the size of the
| universe.
| mordae wrote:
| Just a couple days ago we have programmed rp2040 to drive WS2812B
| LED using assembler, counting clock cycles, with the kids in the
| IT club I run. Not that much harder than playing Shenzhen I/O.
| You should give it a try. :]
| [deleted]
| mordae wrote:
| Modified the C example to avoid compiler being too clever and
| taking zero time.
|
| I get over 3.3 billion additions per second. 550 million is way
| too low.
| nielsole wrote:
| I clicked 1 in the first example because I thought that's the
| number of iterations it would do with -O2.
| BatFastard wrote:
| As a game engine builder, you come to appreciate that your target
| speed to draw millions of polygons, calculate physics on hundreds
| of objects, render the UX, collect network traffic, send network
| traffic, compute pathing, and implement game logic, and
| everything else that needs to be done is 16 milliseconds max.
|
| So I would guess in C++ you could make 240 million calculations
| in a second.
| thfuran wrote:
| A large modern consumer GPU is several to a few dozen
| teraflops.
| BatFastard wrote:
| That is a really bad guess...
| umeshunni wrote:
| What's bad about it?
| CyberDildonics wrote:
| Did you say something ridiculous then reply to yourself three
| minutes later?
| BatFastard wrote:
| Indeed, once I realized the error of my train of thought!
| ChrisArchitect wrote:
| Some previous discussion from 2020:
|
| https://news.ycombinator.com/item?id=23804373
| avgcorrection wrote:
| One second is a really long time UX-wise.
| ilyt wrote:
| It seriously feels like most UI designers don't know that.
| josephg wrote:
| And most web developers don't know that. You want to add 1
| second of page load time to print the time in the correct
| timezone? Noooo! Of course, it's never framed like that.
| People just pull in moment or whatever because that's what
| stack overflow recommends. Moment pulls in the global
| timezone database. You don't notice your javascript bundle
| grow and surprise! Your website sucks.
| troupo wrote:
| Unfortunately, for the longest time ever Moment was the
| only sane date and time library for Javascript.
|
| If you needed more than just adding a single second, you
| were stuck with it.
|
| But size-wise it was ginormous.
| dang wrote:
| Discussed at the time:
|
| _Do you know how much your computer can do in a second?_ -
| https://news.ycombinator.com/item?id=10445927 - Oct 2015 (174
| comments)
| jiggawatts wrote:
| I like to test people's intuition of computer power by asking
| them how many multiplications their phone or PC can make in the
| time it takes light to cross the room.
|
| The way to estimate this is that light takes 3ns to go 1m. If the
| room is 10m wide, that's 30ns. At typical frequencies that's 100
| clocks. With, say, 8 cores that's 800 steps. At each step a core
| can retire about 8 multiplies using AVX vector instructions. The
| estimate of 6,400 multiplications is actually very conservative
| because you also have the GPU! Even low end models can put out
| hundreds of thousands of multiplications in 30ns. High end models
| can do about a million.
|
| When asked, most people estimate "1 to 10". Even programmers and
| IT professionals do not have a mental model of how fast computers
| really are.
| jstanley wrote:
| > Even programmers and IT professionals have literally not
| mental model of how fast computers really are.
|
| Or of how slow light is!
| elboru wrote:
| This site[0] helped me improve my mental model. You can
| scroll through the solar system at scale (the moon being one
| pixel). It takes a while!!
|
| Then you notice a small button at the right bottom corner,
| that button allows you to auto-scroll at the speed of light,
| wow, now that's slow!
|
| [0]https://joshworth.com/dev/pixelspace/pixelspace_solarsyste
| m....
| nomel wrote:
| Makes you realize that space travel isn't going to happen
| with current physics.
| [deleted]
| porphyra wrote:
| The faster you go, the shorter you have to travel due to
| length contraction. So travelling really far distances is
| still possible, for example, by constant acceleration
| [1]. It's just that everyone you left behind will have
| been dead for billions of years by the time you arrive.
|
| [1] https://en.wikipedia.org/wiki/Space_travel_under_cons
| tant_ac...
| [deleted]
| paulddraper wrote:
| Exactly.
|
| Speed of light is not exactly a relatable point of reference.
| arp242 wrote:
| To be honest I think this is almost a trick question, because
| you're combining two very different things (speed of light and
| performance of computers), and people are not very good at
| combining these sort of contexts intuitively (i.e. you need to
| do the calculations).
|
| The other day I was watching The Twilight Zone, and one episode
| involves a crew "655 million miles" from Earth. I know what
| miles are, I know the rough layout and scale of the solar
| system, galaxy, and universe, but I had no idea how far away
| that actually is because it mixes these two units from very
| different contexts and intuitively it just doesn't make sense
| to me; is it still in the solar system? No idea. Converting it
| to AU showed it's about 7 AU, which put it in the appropriate
| context: a bit beyond Jupiter.
| imoverclocked wrote:
| The real question is, "how many Twilight Zone episodes away
| from ubiquitous quantum computing are we?" (is joke)
|
| Units definitely matter but anything outside of our day to
| day experience is difficult to communicate widely. I think
| most people don't know more than Jupiter is actually really
| far away and really really big compared to the Earth. 7 AU
| means nothing to my brain just like 655 million miles. It's a
| computed unit based on mean distance from the center of the
| Earth to the center of the Sun; I also have no idea how far
| we are from the Sun because my brain just experiences a hot
| circle in the sky. The only reason these things seem to make
| sense is because we have seen really vague maps of the Solar
| System. Other falsely but widely-accepted measures include
| using state sizes to describe other regions. People readily
| accept it despite never having been to said state or
| potentially any other state ... or even across their own
| state.
|
| I think these are accepted because of a false confidence in
| understanding (think Dunning-Kruger) based on the fact that
| we have _some_ information.
|
| Personal anecdote: A friend flew from the East coast to
| Arizona and asked if we could just drive to the other side of
| the state to see the Grand Canyon in the evening. I had to
| explain that it's 6 hours one-way despite being in the same
| state. Had I instead said "Arizona is the size of 22
| Connecticuts," the idea of how long it would take to get
| there would still not make any sense.
|
| PS: I said "vague map of the Solar System" because generally
| nothing is always the correct scale. Either the planetary
| distances are the correct scale from each other or the
| planets are the correct scale from each other for pragmatic
| reasons. Sometimes, none of those things are scaled properly.
| Some animations attempt to show things correctly but that's
| still difficult to comprehend because of the non-linear
| velocities required to keep the attention of the viewer.
| aardvark179 wrote:
| What units do you think you know the scale of the solar
| system in? The speed of light is approximately 300 million
| meters per second, so call it 300 thousand kilometres per
| second, or very roughly 200 thousand miles.
|
| Also, if I were asking that sort of question in an interview
| I would fine with a candidate getting a conversion wrong as
| long as they explain their thought process, and I'd help them
| correct the error early. I'm this sort of question is t meant
| to be a trick, it's about whether you can connect different
| variables which may not appear connected at first glance.
| rcoveson wrote:
| Sounds like most people estimate surprisingly well. Fermi-wise,
| the obscure term in your numerator is 10^10 and the obscure
| term in your denominator is 10^8. The more obvious term (room
| size) is 10^1. So the answer is 10^3, and people are guessing
| 10^0 or 10^1. So some people are only off by a couple order of
| magnitude, which is explained by a rather small estimation
| error in either or both obscure terms.
| moffkalast wrote:
| Anyone else having a weird deja-vu moment while reading this?
| cogman10 wrote:
| * Terms and conditions apply
|
| What you are saying is technically true but with HUGE caveats.
| At this point, the issue isn't one of clock cycles but rather
| memory bandwidth and latency. Even assuming the best case, a
| hit in L1 cache, you are looking at +1ns to move the data from
| memory into the registers. But now talk about L2, L3, or worse
| system memory? Oof. And then you mention GPUs, but that problem
| is compounded 10x due to the bandwidth constraints of PCIe.
|
| I mean, sure, if your CPU is doing nothing other than
| multiplying the same value by 2 over and over again, it can do
| that wickedly fast. However, once you start talking about large
| swaths, gigs even, of data to operate against and those numbers
| start to take a precipitous drop.
|
| Heck, one of the benefits of AVX isn't the fact that you can do
| 64 lanes of multiplication at once, but rather the fact that
| you can tell the CPU to grab 64 lanes worth of memory to work
| against at once.
|
| This is why when you start looking at what is talked about when
| people talk about next gen math machines, it's not the FLOPs
| but instead the memory fabric that gets all the attention.
___________________________________________________________________
(page generated 2023-06-22 23:00 UTC)