8 ms·
Alternatively: do you know how much your computer could do in a second, but isn't, because the majority of software is so full of inefficiency? In my experienc
by userbinator 11y ago
Alternatively: do you know how much your computer could do in a second, but isn't, because the majority of software is so full of inefficiency?
In my experience, this is something that a lot of developers don't really comprehend. Many of them will have some idea about theoretical time complexity, but then see nothing wrong with what should be a very trivial operation taking several seconds of CPU time on a modern computer. One of the things I like to do is tell them that such a period of time corresponds to several billion instructions, and then ask them to justify what it is about that operation that needs that amount of instructions. Another thing is to show them some demoscene productions.
I got a few of these questions wrong because I don't use Python, but I could probably say with reasonable confidence how fast these operations could be.
Related articles:
https://en.wikipedia.org/wiki/Wirth%27s_law https://en.wikipedia.org/wiki/Wirth%27s_law
http://hallicino.hubpages.com/hub/_86_Mac_Plus_Vs_07_AMD_DualCore_You_Wont_Believe_Who_Wins http://hallicino.hubpages.com/hub/_86_Mac_Plus_Vs_07_AMD_Dua... (I know title is a BuzzFeed-ism, but this article came from before that era.)
- deleted 11y ago[deleted]
- refurb 11y agoThat's exactly what got me interested in learning x86 assembly language. It's pretty neat to see how fast a generic loop can be when the entire executable is <10 bytes.
- cbd1984 11y agoIs it efficient if it takes so long to get to market that the product is irrelevant by the time it gets there? Is it efficient if the product is buggy and insecure because it's inherently more difficult to program in assembly compared to Python or Java? Is it efficient if the product is not extensible and inflexible because every engineering decision went towards efficiency, which is inherently opposed to flexibility? (Early binding is inherently more efficient than late binding for all the same reasons it is inherently less flexible.) Or do you insist on defining "efficiency" solely to mean "machine efficiency" instead of thinking like an engineer and understanding the concept of trade-offs where no decision is inherently worse than any other?
- vlehto 11y agoI think that attitude is great. It leaves room for the people who think "OK this exists. Now how about making GOOD version of it." Problems start when everybody too perfectionist or everybody is too quick and dirty.
- p1mrx 11y agoThis attitude makes sense within a robust Free Software environment, but if the inefficient component is tied to a proprietary service using a closed protocol, then the ability of any individual to improve that component is very limited.
- cbd1984 11y agoI fully agree with you, and will add one thing: My way leaves room for "OK, this is crap. It isn't worth making a good version of. At least we didn't waste too much time."
- claudius 11y agoIs it efficient to wait 6 weeks for results rather than half a week because you preferred Python over C++ during the half-day (half-week) respectively of coding? Is it efficient to use thousands of kWh in electricity rather than just hundreds? As always, the answer obviously depends on your problem.
- cbd1984 11y agoWhat gets up my nose is when people make it seem like a specific engineering decision is the only moral decision, and that making any other set of trade-offs is evidence of some degeneracy, such as laziness or stupidity. In this context, it's as if they think that, well, "Every cycle's sacred/Every cycle's great/If a cycle's wasted/God gets quite irate" or similar. It's quite annoying to listen to the more extreme end of this spectrum rattle on about how horrible it is that people no longer use self-modifying code with overlapping opcodes and instruction scheduling which optimizes the drum seek time...
- jldugger 11y ago> Alternatively: do you know how much your computer could do in a second, but isn't, because the majority of software is so full of inefficiency? Amusingly, in the first example, the compiler's static analysis concludes that the entire for loop can be omitted. I have no idea how they came up with that precise number...
- radicalbyte 11y agoI had the same problem: of course an empty loop will run at the maximum because any worthwhile compiler would optimize the loop away.
- logicallee 11y agoThe real head-scratcher is why the Python version, whose loop is: def f(NUMBER): for _ in xrange(NUMBER): pass runs one tenth as fast! Is it due to the xrange construct? I'm sure that there must be a saner way to make a loop in Python that doesn't bloat to ten times as many cycles as in C. . .
- reubenmorais 11y ago10x is about what you'd expect for the interpreter overhead in a simple snippet like that.
- andreasvc 11y agoSpecifically, an interpreter without JIT. I'd reckon that LuaJIT or Javascript could come much closer to C.
- reubenmorais 11y agoRight, those are usually called JIT compilers, not interpreters.
- 11y ago
- raverbashing 11y agoTrue It's amazing how somethings are extremely inefficient, and even worse, nobody questions themselves why this is like this Most of 'this is taking too long' is because of IO, still, sometimes it's done in a very inefficient way as well
- pixl97 11y ago>is because of IO Having moved to very fast SSDs and ramdrives in some cases, it amazes me how many applications can't take advantage of them. It's terrible when you have an app that appears to be IO bound on disk and move it to fast drives only to get a 2x speedup, while even a single cpu core isn't maxed out.
- raverbashing 11y agoEven with ssds you can have issues like reading one byte at a time, saturating the sata link, etc
- speeder 11y agoI bought a gaming laptop with a "theoretically" midrange GPU (it is in practice a shitty GPU, nVidia took a true midrange GPU, removed half of the chip, and overclocked it, hoping it will stay with midrange performance, instead the thing just overheats) and a Core i7... It is a waste of money, I rarely see 100% CPU use, the few times I saw 100% CPU use was demoscene stuff, or some russian compression programs (that can do amazing stuff, like compress 60gb downloads into 20gb, but take 2 hours at 100% CPU to decompress). It is evne worse that some games that theoretically would need all the CPU (games that has lots of entitites, or are physics or AI intensive), instead just have thousands of cache misses while they loop through their entities in the memory, and the CPU gets used like 20%. Or they are single-core, even if made recently.
- Tyr42 11y agoI remember fixing a vim plugin that did one system call per character to be received because the IPC returned some number of xml objects, not even wrapped in a top level one, so the plugin didn't want to block by reading past the last > until it processed everything before it. I fixed that to use non-blocking pipes and it was much better.
- crdoconnor 11y ago>Many of them will have some idea about theoretical time complexity, but then see nothing wrong with what should be a very trivial operation taking several seconds of CPU time on a modern computer. In my experience developers who over-optimize, or who optimize with disgusting hacks, are a vastly bigger problem than developers who don't optimize at all. There are a vast number of problems where a several second wait for the user is almost irrelevant compared to the damage done to the code base by optimizing those few seconds away.
- gaius 11y agoNot one-tenth of the problem as people who wrap trivial computations in "enterprise" crapware and use 100x the CPU they really need just to relay a few bytes of data from system A to system B. If you have ever used Java and XML I am looking at you. This has a real cost associated with it, servers, datacentre space, power and cooling, system administrators to look after it all, don't come for free. Not just money, the environment too.
- larsmak 11y agoYes, but this "enterprise" crapware is the transaction system of your bank, and those "few bytes" are your last paycheck. Have some respect for the software that makes the world around you function.
- gaius 11y ago... Which they did perfectly well in the 60s on a mainframe. Why does it take - conservatively estimating - a million times more CPU cycles now?
- praseodym 11y agoThey're most likely still running all their transaction processing on a single mainframe (+another one for redundancy) with something like IBM CICS [1, 2]. And they most likely also have a lot more transactions than in the 60s (card payments, internet banking, etc.). [1] http://www.ibm.com/software/htp/cics/ http://www.ibm.com/software/htp/cics/ [2] https://en.wikipedia.org/wiki/CICS https://en.wikipedia.org/wiki/CICS - yes, "Initial release: 1968; 47 years ago"
- gaius 11y agoAgree 100%. As a hobby I like to hack 6502 assembly language on original hardware, I have Beebs, Ataris, VIC20 and C=64. 2Mhz is the limit. It is amazing to modern eyes how much computation on these systems you can get done once you strip away all the layers of abstraction and indirection modern systems are saddled with.
- yason 11y agoThe inefficiency of computing platforms is like the amount of congestion. Both expand to the level of being just barely bearable. If a computer is too slow nobody will use it; if it's only irritatingly slow, some will use it and; if it's slow but still bearable enough, everybody grumbled but still uses it. Development costs and building programs with higher level languages and using big, high-level frameworks saves in development but increases the cost of using the system. The result is that some majority of programs will always be optimized only to the point where they are barely usable. Similarly, when traffic is always as congested as the people on roads can bear: those will drop out who really hate congestion or prefer to do their trip at another trip but they will be replaced by people who are willing to pay the time tax again. When space is freed on the highway or arterial road, some people will figure out it's worth the trouble and head out. This means you can't make the user experience faster by getting faster computers and you can't build more roads and lanes to get rid of congestion. But there's more. Because a large mass of congested traffic is more difficult to separate and channel into exits congestion on large roads tends to be worse. If you have a village main street with one lane each way on a road, and that road gets traffic congestion that's much less total congestion, area-wise, and it will clear up pretty quickly once the head of traffic is able to exit somewhere. Even so with a grid of 1+1 lane streets, like in a small town. Because the small road gets quickly congested it will only swallow a limited number of cars which will keep a bound on the maximum amount of congested area. Not so with a 10+10 lane highway. Similarly to computer programs. Slow programs in the early times when everything was simpler could be made faster with sufficient effort. The programs might still struggle in some parts but you could at least invest in the effort to streamline the core operations and make the worst things fast enough. In contrast, consider an enterprise Java program that depends on dozens or hundreds of libraries that amount to a running image of the size of half-a to a whole gigabyte. It takes ten seconds to start and opening each window takes seconds because there's slack everywhere. Everything runs top of something else and even simple operations involve running mundate pieces of code for seconds in wallclock time. Because the computer that's fast enough to run the program in the first place also has the computing power to run a lot of crap in a similar manner. So the amount of crap just increases as the computing power increases, and getting rid of that crap becomes an unsurmountable task. So it becomes close to impossible to make such a big program run fast because you would have to shrink everything between the application and the hardware in half or in one tenth to get some sort of speed. Coincidentally, old computer systems often had faster user interface latency and responded to user inputs in a very timely manner. They could do the cheap things really fast even if the total lack of computer power still made the programs spend seconds on the heavy processing.
- pjc50 11y agoThe situation gets even more extreme when you consider graphics cards, and their ability to do thousands of operations per screen pixel per frame. I like your Mac Plus article; that reminds us that the user experience has not got necessarily got better with all this processing power.
- skimpycompiler 11y agoThe situation gets even more extreme when you consider FPGAs. Having done Mandelbrot set as a toy example, it worked faster than a graphics card at producing high-resolution images and zooms.
- speeder 11y agoI am a programmer, I also like to play games, and make them. I own a ASUS gaming laptop, and I got astonished by how badly newer games run, even games with graphics that are like of 20 years ago (example: I really like business simulation games, some use isometric graphics with some extremely low poly and untextured models for the walls and floors and some objects, like plants and tables) run slow on my machine. Even some 2D games run badly, Axiom Verge had several slowdowns on my machine, Luftrausers is virtually unplayable (when there is heavy firefighting on the screen, the game starts to lag severely, things start to teleport around the screen), Wasteland 2 runs like crap and bugs out like crazy (transparent walls, grass growing on random places, people disappearing). Even games from legendary companies in the technical sense are not doing well, for example I tried to run the new Wolfenstein game on my machine, even at the lowest settings possible the thing go at 3 FPS. Meanwhile I can play emulated Wii games (Xenoblade for example) with 60 FPS, Stalker series (that in my opinion have amazing graphics) I could even place some mods to make it prettier without losing too much FPS, games using Source engine can confortably run with all the bells and whistles, and so on... But try to play a new game, even a 2D one, say, Pillars of Eternity. The thing manages to lag for no reason. I noticed one reason for this is the abuse of Garbage Collectors, many of the games I had problems with has Garbage Collectors, and I see the memory swinging all over the place (a particularly bad one: Kerbal Space Program, it loads everything on launch, then unloads things, then load again as needed, when I launch it, it hits 3gb of memory, then as I use it slowly decrease, then it starts increasing again for no reason, I assume due to memory leaks, and crashes), I even started to play games with the windows task manager on the second monitor, with apps ordered by memory use, this way I know when they will run out of memory and crash (thus I can save first). And then, there are the devs attitude toward optimization, I finished two days ago some ARM NEON code for my iPhone project (I am doing some freelance iOS coding now), I decided to discuss it on IRC, and some devs got pissed off, they tried to convince me that Apple native APIs were better, and that I was doing my design all wrong, and that instead of using a single ASM function that do all the operations I need inside a single loop, I should have used a collection of Apple APIs that would involve 4 different objects layered to the same thing... When I explained that my original code (that was using OpenCV), was too slow according to the profiler (it was using 60% of the CPU time), they replied that I was "optmizing the wrong place". Also when I mention I plan to make it work on iPod 5 and iPhone 4, people counter-argue that I should just ignore those and make it run on iPhone 6 only, because that is the proper solution for not having enough CPU (instead of getting the CPU manual and doing decent code).
- bikeshack 11y agoSome of the work of Distributed.net ( http://www.distributed.net/Main_Page http://www.distributed.net/Main_Page ) is wonderful. Does anyone know if this idea could be more than it is currently, where computers (more than ever) are sitting idly and not contributing their cycles in any meaningful way? Even 5 minutes of raw CPU 100% usage per device could do some serious computation. Theoretically superseding modern supercomputers.
- cowsandmilk 11y agoboinc, folding@home, gimps, etc. have all done this for over a decade.
- fho 11y agoThing is that when boinc and co were popular all those cycles were really wasted. Today computers just enter power-saving states when not in use saving electricity and in effect money.
- pjc50 11y agoComputers more than ever rely on not being at 100% CPU all the time, because the increased power consumption and heat dissipation is a problem. Instead it's all about the "race to idle": do the work and then go to sleep for a few miliseconds to cool down.
- reubenmorais 11y agoCase in point: with my MBP battery, I can get 8 hours of browsing the Web, reading articles, watching a YouTube video or another. But if I spin a parallel build that uses 100% of all cores for about 15 minutes, I eat through half of my battery life.
- agumonkey 11y agoI wonder what's the sleep-state/consumption curve. Linear or not.
- rasz_pl 11y agoLAME. What you want is a javascript heavy web UI driven by nodejs server, all running on same underpowered embedded platform. At least 5 levels of abstraction above decency, because hey, we can iterate quickly and hardware is cheap!!1
- ownagefool 11y agoIt's because the extra slowness is supposed to be buying us software thats safer and easier to write. The argument has never been about how fast can we be, it's about being fast enough where the cost of talent completely annihilates the cost of compute. If I were writing some python, which means I've already made that trade off, you wouldn't much like my answer if you started asking me such questions. Which is a shame because I'd probably rather have quite a lot of respect for the same point if we were working lower down the stack.
- Lukas_Skywalker 11y agoSlightly related: back in 2003, pg has written an essay about programming languages. A few paragraphs talk about wasting cycles and how it also occurs in other fields than programming: http://www.paulgraham.com/hundred.html http://www.paulgraham.com/hundred.html
- novaleaf 11y agoC# is a pretty good example of where the tradeoff between speed and safety can be a good choice. I wrote a non-trivial stock trading app in C#, and for sake of this conversation I added some loop counting. it analyses about 1.5million ticks per-second (against trade rules). This is a single thread running on a 3.2ghz core i5, no I/O.
- DigitalJack 11y agoWhat I'd like to know is how this plays out at the operating system level. We can run cachegrind on a program, but it doesn't take into account the effects of task switching of the OS (as far as I know). I think it would be lovely in these multicore days if we could dedicate a core to a process and have as close to 0 task switching as possible on that core.
- hyperpape 11y agoPretty sure it's possible: http://xmodulo.com/run-program-process-specific-cpu-cores-linux.html http://xmodulo.com/run-program-process-specific-cpu-cores-li...
- DigitalJack 11y agoThat's close, but I think it is only half the equation. The other half would be granting exclusivity to that process for the core, not just affinity.
- hyperpape 11y agoIsn't that the isolcpus command it mentions at the bottom? Btw: this was just a quick google search, I've never done this. But I'm pretty sure I've heard Martin Thompson discuss it.
- DigitalJack 11y agoYou are absolutely right. I stopped reading before I got to the bottom. That's really neat!
- velox_io 11y agoThere was an article on how much can your computer do 400 cycles (a cache miss) recently. I have noticed that the size of L2 caches hasn't increased anywhere near the same rate as other memory capacity. http://www.slideshare.net/EmanWebDev/pitfalls-of-object-oriented-programminggcap09 http://www.slideshare.net/EmanWebDev/pitfalls-of-object-orie...