10 ms·
Do you know how much your computer can do in a second? (2015)
- roninkoi 3y agoWhat surprised me the most is how fast grepping is. It can search more bytes from memory than iterations in a simple for loop?
- taldo 3y agoProbably 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 3y agoGrep 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 3y agoI 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 3y agoDepending 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 3y agoEspecially ripgrep! All hail ripgrep! I will never go back to not using it.
- burntsushi 3y agoIt 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.
- littlestymaar 3y ago(For those unaware, burntsushi is the author of ripgrep)
- xeonmc 3y agosource? (edit: was supposed to be a pun)
- paraselene_ 3y agoThis should suffice? https://github.com/BurntSushi/ripgrep https://github.com/BurntSushi/ripgrep
- deleted 3y ago[deleted]
- slyall 3y agoThe loki logging software takes advantage of how fast grepping is. Instead of have a big index that lets you locate the exact line you are looking for it has a much small index of tags. The tags ( something like env=prod, app=auth ) will narrow things down to say 1% of the data in the time period. The software then just greps though a few Gigabytes to find the exact lines you are after.
- nathants 3y agogrep is the beginning, not the end. it’s a great performance baseline to meet, and then beat[1]. computers are insanely fast! the startups using grep on aws are undercutting those doing slower things on aws. i wonder why aws architects never talk about grep. 1. https://github.com/nathants/bsv https://github.com/nathants/bsv
- deleted 3y ago[deleted]
- mordae 3y agoModified 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 3y agoI clicked 1 in the first example because I thought that's the number of iterations it would do with -O2.
- BatFastard 3y agoAs 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.
- BatFastard 3y agoThat is a really bad guess...
- CyberDildonics 3y agoDid you say something ridiculous then reply to yourself three minutes later?
- BatFastard 3y agoIndeed, once I realized the error of my train of thought!
- masfuerte 3y agoYou can edit comments. An explanatory P.S. is much clearer than a reply to yourself.
- umeshunni 3y agoWhat's bad about it?
- thfuran 3y agoA large modern consumer GPU is several to a few dozen teraflops.
- jiggawatts 3y agoI 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 3y ago> Even programmers and IT professionals have literally not mental model of how fast computers really are. Or of how slow light is!
- deleted 3y ago[deleted]
- paulddraper 3y agoExactly. Speed of light is not exactly a relatable point of reference.
- jiggawatts 3y agoIt ought to be intuitive for everyone working in software development! The performance of everything is limited in one way or another by ‘c’. Not just WAN links, but the data centre Ethernet as well. The distance to the disks matters. The physical size of the motherboard. The placement of caches, etc… When people say things like “putting the compute near the data” they’re implicitly talking about overcoming the limits imposed by the speed of light. When you hear about an N+1 performance issue in some ORM, that’s bad because of the speed of light. When you test your LAN with “ping”, you’re lying to yourself because it won’t show measurements below 1 ms, which is an eternity. I just told you how much compute can occur in just 10 nanoseconds. Go ping something. Look at the “1 ms” in the output. Go back to my post and work out what can occur in 1,000,000 nanoseconds. Go look at the 1 ms again. Repeat until you have an epiphany about your zone redundant Kubernetes-hosted cloud native microservices architecture.
- mordae 3y agoJust 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. :]
- dang 3y agoDiscussed at the time: Do you know how much your computer can do in a second? - https://news.ycombinator.com/item?id=10445927 https://news.ycombinator.com/item?id=10445927 - Oct 2015 (174 comments)
- userbinator 3y agoIt's interesting to read the comment I made there almost 8 years ago and think "computers certainly don't feel like they've gotten any faster since then --- if anything, they've become even slower." Software has certainly gotten slower more quickly than hardware getting faster.
- globular-toast 3y agoMost of this is not really "computers are fast" but rather "algorithms are cool". That's fine, of course.
- ChrisArchitect 3y agoSome previous discussion from 2020: https://news.ycombinator.com/item?id=23804373 https://news.ycombinator.com/item?id=23804373
- mud_dauber 3y agoI 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?
- shpx 3y agoI had a similar thought from this video counting CPU interrupts in one key press on the 6502 https://youtu.be/DlEa8kd7n3Q?t=12m52s https://youtu.be/DlEa8kd7n3Q?t=12m52s In one second I can type about 7 ASCII characters, read maybe 20, or aim and click like twice. Each typed character is worth like 600 million CPU instructions of a single core of a 4GHz CPU. It's actually this fat, precious thing, the product of a giant computation from a "computer" (that was optimized for something else) that we aren't harnessing at anywhere near its real value. Instead, we type semicolons.
- JohnFen 3y agoI can grasp it about as well as I can grasp the size of the universe.
- von_lohengramm 3y agoI really dislike the `fill_array.c ` vs `fill_array_out_of_order.c ` example. While it's showing the effects of spatial locality, it's misattributing the performance delta to the CPU L1/L2 cache. The problem is that it's filling an array in freshly allocated memory. While you might expect `malloc(NUMBER)` to give your process a crap ton of space in your RAM, that's far from the truth. First of all, glibc will just translate that into an `mmap`, and even if it didn't, the Linux kernel still wouldn't allocate the whole buffer due to "optimistic memory allocation." Instead, you'll receive ownership of this chunk of virtual memory, but you won't actually allocate anything at first. Only when you dirty each page will it actually allocate the backing physical memory. And even then, the Kernel has various heuristics to preemptively page in memory that it thinks you're going to use soon. I'm sure the author was aware that the example was more nuanced than just "muh CPU cache", but reducing spatial locality to just "muh CPU cache" for the article's sake does a disservice to the reader.
- eldenring 3y agoI mean you'd get the same number of page faults with both examples, so I think the discrepency is explainable by caches/cpu prefetching.
- mitchs 3y agoThe doubling of J as a means of striding across the array also gives me some concern. While it is cache related, it is cache related for sneaky reasons. J is going to end up, in binary, with a ton of 0s at the end after being doubled over and over. After 6 iterations after each reset, the position within the cache line is guaranteed to be 0. Using the standard 32K of L1 D$ would be 512x64 byte lines. Assuming 8-way associative (decently common as far as I know) means these 512 lines are organized into 64 set indexes, each with 8 lines. So after the next 6 post-reset iterations you are guaranteed to only be hitting the 0th index into the cache, effectively reducing the L1 cache size to 8 lines. (edit: Not the 0th index, but the same index as the base of the array.)
- ReactiveJelly 3y agoDo the caches really just use the last few bits and not any kind of small hash function?
- deleted 3y ago[deleted]
- kazinator 3y ago> Do you know how much your computer can do in a second? Make about 25% progress toward the start menu popping up after the click on the button.
- hatthew 3y agoI fixed that on my computer by turning off start menu web search, IIRC something like this: https://pureinfotech.com/disable-search-web-results-windows-11/ https://pureinfotech.com/disable-search-web-results-windows-...
- syngrog66 3y agoI've been studying and writing about this exact issue recently, for a big side project of mine.
- ks2048 3y agoI just wrote a blog post [0] on a project that I did with audio-fingerprinting and to my surprise, my desktop could do 369 billion bit-comparisons per second (popcnt using AVX2 instructions, 4 simultaneous processes). [0] https://kenschutte.com/phingerprint/ https://kenschutte.com/phingerprint/
- mieubrisse 3y agoIs there a bug with write_to_memory.py? (SPOILER BELOW) loop.py does 68 million operations per second, and the text below says "we know about the most we can expect from Python (100 million things/s)", but write_to_memory.py writes 2 billion bytes per second writing one byte at a time. How can writing to memory be faster than doing nothing?
- rsfern 3y agoI wasn’t sure what the units were on that one, since the chunk size is more than one byte. So NUMBER is the iterations, but I guess they’re looking for an answer in bytes, and it’s much less than 100M iterations?
- thundergolfer 3y agoYes there’s a bug: https://thundergolfer.com/performance/profiling/2022/08/05/stringio-bytes-written-per-second/ https://thundergolfer.com/performance/profiling/2022/08/05/s...
- tomcam 3y agoI have Xfinity, so I know exactly how much my computer can do in a second: load 1/30 of the Reddit homepage on a 300Mbs connection
- nwellinghoff 3y agoYes. Exactly what it could do in 2004 but 10x slower with 1000x the computing power. #bloat
- Aeolun 3y ago10/18 Could have been worse. Only a few were off by more than one order of magnitude (mostly I underestimate just how fast md5 is).
- bandrami 3y agoI still have the "nanosecond" (11.8 inches of copper strand) Admiral Hopper gave out when I saw her lecture back in the 80s.
- bmacho 3y agoRender 1/4th of a webpage?
- DeathArrow 3y ago>Do you know how much your computer can do in a second? Not much if you are running Electron apps.
- bob1029 3y agoYes. I know it can render 100 frames of a high quality 3d scene along with related networking, audio, logic, physics, etc. operations. I don't need a website to tell me my computer is fast. What I need is a website that spoonfeeds "how to make webapp feel like Q3A" to the average developer and somehow keeps them on objective. You really should be able to constantly shame yourself into focus on this. "Is rendering this report table more complicated than a scene from Overwatch?" You will likely answer "no", hang your head in shame for a moment, and then admit to yourself you need to throw away your stack of 20+ 3rd party js libs and break out the MDN bible.
- AnIdiotOnTheNet 3y ago> "Is rendering this report table more complicated than a scene from Overwatch?" You will likely answer "no", hang your head in shame for a moment Hell, even just asking if it is more complicated than DOOM should illicit an even more appropriate level of shame. DOOM ran on a 386 with 4MB of RAM and 12MB of disk.
- ForOldHack 3y agoI was surprised that I got every single one, but 1. Just know about performance and networking. Never considered the speed of light, but... I did point out to the docent at CHM what one of Grace Hoppers nano seconds was. I saw one of those in Time-Life book in the 1960s. I bet she would have done well at this quiz, and it was very good.
- LLyaudet 3y agoSPOILER ALERT Am I the only one who thought "What's the problem? - The basic loop with xrange in Python tops at 68,000,000 (loop.py), - but write_to_disk.py tops at 342,000,000, - and write_to_memory.py tops at 2,000,000,000 " ? And then thought "Ahah but it is while loops instead of iterators! Iterators are that bad for performance! XD"
- avgcorrection 3y agoOne second is a really long time UX-wise.
- ilyt 3y agoIt seriously feels like most UI designers don't know that.
- josephg 3y agoAnd 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 3y agoUnfortunately, 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.
- Hermitian909 3y agoIME many web developers do know, but don't do anything because of incentives. Leadership rarely uses the surfaces you make slow, and people don't generally report an extra half second of latency. So their incentive structure looks like: 1. They will not be rewarded for going the extra mile 2. They will not be punished for making the site slower 3. They will be punished for shipping the feature slower Point out "X will be slow" to a lot of devs and they go "I know, but I don't have bandwidth to prioritize the extra work" Part of why it's so important to make the right thing easy.
- ilyt 3y agoA few, maybe. Most just want to get paid and dont give a shit. Which is normal.
- herpderperator 3y agoI 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.
- sublinear 3y agoWhy 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 3y agoI 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 3y agoI 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 3y agoI 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 3y agoThat'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.
- weatherlight 3y agoI think the point I'm making is that there's nothing "universal" about a language that makes it easier to learn then other languages. It's what ever your previous experience is. In my point, I rebuttal that non programmers would find python "easy to read", kinda not true. I then use my exposure to Go as antidotal evidence, of the above observation.
- ilyt 3y agoLoad half a webpage sadly... The only thing I learned is apparently default Python JSON lib sucks on speed
- dan-robertson 3y ago50MB/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 3y agoThe 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.
- dan-robertson 3y agoI think it’s ‘thermally limited and a few years old’ which makes it a bit slower than I expected. I’ll accept that ‘old’ was a bad characterisation.
- ilyt 3y agoI probably underestimated how much does it take to convert it from "fast JSON decoder written in C" (which many interpreted languages use in backend) to actual language implementation, but in perl it's pretty fast: -> ᛯ ls -s -h big.json 101M big.json [11:53:30] ^ [/tmp] -> ᛯ cat /tmp/1.pl #!/usr/bin/perl use v5.24; use JSON::XS; use File::Slurp; my $j = decode_json(read_file('/tmp/big.json')); say scalar @{$j->{'a'}} [11:53:39] ^ [/tmp] -> ᛯ time /tmp/1.pl 34952534 /tmp/1.pl 0,81s user 0,13s system 99% cpu 0,939 total so just around 100MB/s
- Measter 3y agoFor comparison, using Rust's Serde-Json library on my desktop (Intel 11700k, and with computer doing other things), benchmarked with Criterion: Benchmarking json_read_struct: Collecting 100 samples in estimated 5.2012 s (81k iterations) json_read_struct time: [64.126 µs 64.376 µs 64.660 µs] change: [+0.2646% +0.7525% +1.2538%] (p = 0.00 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 6 (6.00%) high mild 1 (1.00%) high severe My benchmark code[0] takes advantage of knowing the shape of the data, and also knowing that I can avoid allocations for the strings so we're not measuring the allocator performance. With 64 microseconds per iteration, that comes out to about 15,600 parses per second. [0] https://gist.github.com/Measter/acbae474ba8e1451946630da2a2cb177 https://gist.github.com/Measter/acbae474ba8e1451946630da2a2c...
- jamestimmins 3y agoThis 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 3y ago> 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 3y agoFor 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.
- pjscott 3y ago“Practically human speed” is exactly what they’re aiming for. It’s meant to be used in human-speed applications, and to be as slow as possible in those use-cases without causing perceptible lag.
- stavros 3y agoThe 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).
- hatthew 3y agoThis one threw me off as well. I didn't see any configuration so I just assumed that it was only 1 iteration by default. After being off by several orders of magnitude, I looked it up and apparently it defaults to 4096 iterations.