News for hackers. Stuff that matters.
Re:Do you know how much your computer can do in a second? by userbinator on Sunday October 25, 2015 @01:20AM (#10446070)
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

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.)

Re:Do you know how much your computer can do in a second? by ownagefool on Sunday October 25, 2015 @11:54AM (#10447191)
It'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.

Re:Do you know how much your computer can do in a second? by Lukas_Skywalker on Sunday October 25, 2015 @03:20PM (#10447992)
Slightly 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
Re:Do you know how much your computer can do in a second? by jldugger on Sunday October 25, 2015 @04:18AM (#10446331)
> 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...

Re:Do you know how much your computer can do in a second? by CydeWeys on Sunday October 25, 2015 @09:36AM (#10446831)
Presumably they passed flags to gcc (or whichever compiler they used) to disable these optimizations, otherwise, you're right, they wouldn't make much sense if the code wasn't actually being run as presented.
Re:Do you know how much your computer can do in a second? by kbenson on Sunday October 25, 2015 @04:44PM (#10448332)
Interestingly, there's quite a bit that's needed to ensure you bypass some compiler optimizations. Here's an ey-opening (for me) talk[1] on benchmarking C++ and compilers which touched on it.

1: https://www.youtube.com/watch?v=nXaxk27zwlk

Re:Do you know how much your computer can do in a second? by radicalbyte on Sunday October 25, 2015 @06:59AM (#10446599)
I had the same problem: of course an empty loop will run at the maximum because any worthwhile compiler would optimize the loop away.
Re:Do you know how much your computer can do in a second? by logicallee on Sunday October 25, 2015 @09:17AM (#10446794)
The 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. . .
Re:Do you know how much your computer can do in a second? by ProblemFactory on Sunday October 25, 2015 @09:37AM (#10446834)
It runs at 1/10 speed because it's interpreted bytecode, and it allocates a new PyInt object for each number in the loop.

You can get it back close to native speed by adding a type annotation and compiling the python file with Cython: http://docs.cython.org/src/userguide/language_basics.html#in...

    def f(NUMBER):
        cdef int i
        for i in range(NUMBER):
            pass
Re:Do you know how much your computer can do in a second? by andreasvc on Sunday October 25, 2015 @11:08AM (#10447056)
Not just close to native speed, this will get you the exact same C code for the inner loop.
Re:Do you know how much your computer can do in a second? by mulander on Sunday October 25, 2015 @10:36AM (#10446957)
I wonder if [x for x in xrange(NUMBER)] would be any faster. Yes it allocates an array but list comprehension is executed differently by python. I recall a talk by some Dropbox guy stating that it was one of their optimization strategies.

Didn't find the original talk but found this: https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Loo...

Re:Do you know how much your computer can do in a second? by andreasvc on Sunday October 25, 2015 @11:11AM (#10447065)
Nitpick: that creates a list, not an array. It could be faster, but it's not the same benchmark. When you get to the point where the speed of loops matters it's better to reach for Cython, Numba, PyPy, etc.
Re:Do you know how much your computer can do in a second? by dalke on Sunday October 25, 2015 @07:10PM (#10448845)
Why wonder when you can test?

    % python -mtimeit '[x for x in xrange(1000)]'
    10000 loops, best of 3: 70.2 usec per loop
    % python -mtimeit 'for x in xrange(1000): pass'
    10000 loops, best of 3: 29 usec per loop

    % python -mtimeit '[x for x in xrange(100000)]'
    100 loops, best of 3: 7.03 msec per loop
    % python -mtimeit 'for x in xrange(100000): pass'
    100 loops, best of 3: 2.5 msec per loop
Re:Do you know how much your computer can do in a second? by reubenmorais on Sunday October 25, 2015 @09:23AM (#10446809)
10x is about what you'd expect for the interpreter overhead in a simple snippet like that.
Re:Do you know how much your computer can do in a second? by cma on Sunday October 25, 2015 @04:00PM (#10448155)
Unfortunately python doesn't use a tagged pointers optimization even though I believe pointers are always aligned so there are some spare bits that could be used to indicate pointer vs. int.

I think the only reason they haven't is the legacy C interface; it's a shame they didn't do it for Python 3, but I guess it could have delayed conversion of c libraries even more.

Re:Do you know how much your computer can do in a second? by andreasvc on Sunday October 25, 2015 @11:13AM (#10447072)
Specifically, an interpreter without JIT. I'd reckon that LuaJIT or Javascript could come much closer to C.
Re:Do you know how much your computer can do in a second? by warbiscuit on Sunday October 25, 2015 @04:21PM (#10448237)
For me, running their sample script using the PyPy JIT resulted in a 12x speedup compared to cpython.

Though that still wasn't as fast as gcc on my system (core i5 3.4ghz; using 1e8 rounds):

* cpython 2.7.4 - 1.131s

* pypy 2.6.0 - 0.090s

* gcc w/ "-O2" - 0.050s

Re:Do you know how much your computer can do in a second? by reubenmorais on Sunday October 25, 2015 @11:58AM (#10447202)
Right, those are usually called JIT compilers, not interpreters.
Re:Do you know how much your computer can do in a second? by andreasvc on Monday October 26, 2015 @03:10PM (#10453689)
The distinction is not all that useful, and is blurred nowadays. You could say that CPython compiles code to bytecode, but the bytecode is then interpreted; however, none of that matters, because it's doing very little optimization and that means it's slow. Javascript is typically also not compiled ahead-of-time to native code, but it can still be very fast because of JIT; at the same time it's still very much a dynamic language which makes it share features with interpreted languages.

I'd say JIT is neither about compilation nor interpretation, but about optimization.

Re:Do you know how much your computer can do in a second? by gaius on Sunday October 25, 2015 @05:27AM (#10446447)
Agree 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.

Re:Do you know how much your computer can do in a second? by pjc50 on Sunday October 25, 2015 @06:19AM (#10446523)
The 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.

Re:Do you know how much your computer can do in a second? by skimpycompiler on Sunday October 25, 2015 @10:40AM (#10446970)
The 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.
Re:Do you know how much your computer can do in a second? by speeder on Sunday October 25, 2015 @12:20PM (#10447276)
I 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).

Re:Do you know how much your computer can do in a second? by pjc50 on Sunday October 25, 2015 @03:46PM (#10448092)
Righteous rant, and absolutely right: there isn't really any excuse for a 2D game being slow these days. I suspect some of this is due to unpredictability of GPU performance; that's why the nvidia driver ships with 300Mb of compatibility shims.
Re:Do you know how much your computer can do in a second? by animal531 on Monday October 26, 2015 @06:47AM (#10450537)
A lot of modern games run slow because devs are using common 2D/3D engines which focus on cross-compatibility and ease of use over speed.

Testing in a lot of basic 2D engines also focuses on low performance, e.g. for an RPG where you'll have a dozen sprites moving around, instead of say 500 ships/weapon shots in a shmup.

Re:Do you know how much your computer can do in a second? by bikeshack on Sunday October 25, 2015 @08:04AM (#10446699)
Some of the work of Distributed.net ( 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.
Re:Do you know how much your computer can do in a second? by pjc50 on Sunday October 25, 2015 @08:54AM (#10446761)
Computers 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.
Re:Do you know how much your computer can do in a second? by reubenmorais on Sunday October 25, 2015 @09:26AM (#10446814)
Case 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.
Re:Do you know how much your computer can do in a second? by agumonkey on Sunday October 25, 2015 @07:48PM (#10448931)
I wonder what's the sleep-state/consumption curve. Linear or not.
Re:Do you know how much your computer can do in a second? by userbinator on Sunday October 25, 2015 @10:06AM (#10446888)
The difference between idle and full power is very large in modern CPUs - a typical laptop one can consume an average of a few watts at idle, but several dozen at full load; furthermore, they can switch between these states thousands of times per second. This is why CPU power circuitry is not easy to design, since it has to keep up with the very fast changes in current as the CPU transitions between power states.

Incidentally, this is also why you may be able to hear audible sounds from a computer when it's idle or running some particular process - the wakeups/sleeps are happening at a frequency in the hearing range, and the components like capacitors and coils can act as tiny speakers.

Re:Do you know how much your computer can do in a second? by cowsandmilk on Sunday October 25, 2015 @08:27AM (#10446724)
boinc, folding@home, gimps, etc. have all done this for over a decade.
Re:Do you know how much your computer can do in a second? by fho on Sunday October 25, 2015 @08:44AM (#10446750)
Thing 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.
Re:Do you know how much your computer can do in a second? by Johnny_Brahms on Sunday October 25, 2015 @01:39PM (#10447595)
Distributed.net is the only program capable of maxing out all my 8 cores. Not even transcoding video does that. Pretty cool.
Re:Do you know how much your computer can do in a second? by semi-extrinsic on Sunday October 25, 2015 @04:42PM (#10448326)
This is because Intel is tricking you with the core count. I'm guessing you have an i5/i7/whatever with 8 cores but just two memory channels. Since it only takes two or three cores to saturate those memory channels, you will never be able to max out 8 cores on anything that processes much more than $CACHE_SIZE (~4MB) of data. So you can use 8 cores for stuff like finding primes or bruteforcing RC5 (like distributed.net), but not much else.
Re:Do you know how much your computer can do in a second? by Johnny_Brahms on Monday October 26, 2015 @03:48AM (#10450013)
Ah! Thanks. What would I go for if I wanted to actually use that much data? POWER8?
Re:Do you know how much your computer can do in a second? by semi-extrinsic on Monday October 26, 2015 @08:09AM (#10450817)
Depends on what you want and how much money you want to spend. If your workload is embarrasingly parallel, it could be cheaper to buy several servers with a CPU like the Xeon E5-1630 v3 (Edit: which has just 4 cores and 4 mem channels). Or, as you say, go the POWER8/SPARC route, which also includes the recent option of a single x86 server with up to 8x Xeon E7-8893 v3. For the latter option you may hit NUMA issues as well; depends on your workload.

Your choice boils down to the classic "message passing" vs. "shared memory" (think MPI vs. OpenMP) architectural choice. What the optimal solution is depends on the specific application, as well as how far you want to scale it.

Re:Do you know how much your computer can do in a second? by cbd1984 on Sunday October 25, 2015 @02:57AM (#10446227)
Is 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?

Re:Do you know how much your computer can do in a second? by claudius on Sunday October 25, 2015 @05:14AM (#10446425)
Is 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.

Re:Do you know how much your computer can do in a second? by cbd1984 on Sunday October 25, 2015 @06:36AM (#10446557)
What 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...

Re:Do you know how much your computer can do in a second? by claudius on Sunday October 25, 2015 @07:24AM (#10446645)
Oh, absolutely. But equally absolutely, there are no absolutes. There’s still plenty of areas where fast code is infinitely more valuable than anything else, including developer time. As I said, whether you should optimise for the former or the latter strongly depends on your problem at hand and external circumstances. PhD students are cheap, Xeons aren’t.
Re:Do you know how much your computer can do in a second? by blub on Sunday October 25, 2015 @04:11PM (#10448198)
These people are rarer and rarer. On HN I always see the top comments excusing poor performance with having supposedly better productivity and security.

It really seems that many devs are allergic to the word "optimisation" and lash out when they see it. No one says you have to write your code in assembly folks, but do run it in a profiles and make sure it's now slow.

Re:Do you know how much your computer can do in a second? by userbinator on Sunday October 25, 2015 @07:48AM (#10446683)
Re:Do you know how much your computer can do in a second? by vlehto on Sunday October 25, 2015 @04:01AM (#10446305)
I 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.

Re:Do you know how much your computer can do in a second? by p1mrx on Sunday October 25, 2015 @04:28AM (#10446345)
This 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.
Re:Do you know how much your computer can do in a second? by cbd1984 on Sunday October 25, 2015 @05:25AM (#10446443)
I 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."

Re:Do you know how much your computer can do in a second? by raverbashing on Sunday October 25, 2015 @05:16AM (#10446428)
True

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

Re:Do you know how much your computer can do in a second? by pixl97 on Sunday October 25, 2015 @11:08AM (#10447058)
>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.

Re:Do you know how much your computer can do in a second? by speeder on Sunday October 25, 2015 @12:26PM (#10447295)
I 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.

Re:Do you know how much your computer can do in a second? by raverbashing on Sunday October 25, 2015 @11:56AM (#10447195)
Even with ssds you can have issues like reading one byte at a time, saturating the sata link, etc
Re:Do you know how much your computer can do in a second? by Tyr42 on Sunday October 25, 2015 @11:28AM (#10447116)
I 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.

Re:Do you know how much your computer can do in a second? by novaleaf on Sunday October 25, 2015 @02:53PM (#10447876)
C# 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.

Re:Do you know how much your computer can do in a second? by refurb on Sunday October 25, 2015 @02:27AM (#10446173)
That'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.
Re:Do you know how much your computer can do in a second? by yason on Sunday October 25, 2015 @06:13AM (#10446519)
The 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.

Re:Do you know how much your computer can do in a second? by ZenoArrow on Sunday October 25, 2015 @09:18AM (#10446796)
There's an element of truth to what you say, but I think software efficiency will increase in importance over time, especially when the limits on Moore's law are too expensive to overcome.
Re:Do you know how much your computer can do in a second? by DigitalJack on Sunday October 25, 2015 @05:13PM (#10448450)
What 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.

Re:Do you know how much your computer can do in a second? by hyperpape on Sunday October 25, 2015 @07:04PM (#10448831)
Re:Do you know how much your computer can do in a second? by DigitalJack on Sunday October 25, 2015 @08:48PM (#10449088)
That'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.
Re:Do you know how much your computer can do in a second? by hyperpape on Monday October 26, 2015 @02:06PM (#10453157)
Isn'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.

Re:Do you know how much your computer can do in a second? by DigitalJack on Tuesday October 27, 2015 @12:20AM (#10456302)
You are absolutely right. I stopped reading before I got to the bottom. That's really neat!
Re:Do you know how much your computer can do in a second? by crdoconnor on Sunday October 25, 2015 @05:19AM (#10446433)
>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.

Re:Do you know how much your computer can do in a second? by lhecker on Sunday October 25, 2015 @06:23AM (#10446530)
So your opinion is "If it's slow it's okay, because it's safer than optimizing?".

I'm sorry but I have to disagree completely...

I'm currently rewriting the node-postgres module from scratch and my implementation is between 3 and >1000 times faster than the original (this is not even a joke). And you know why? Because the original actually contains those hacks you're talking about and not the other way around.

And that's where your actual noticable inefficiencies far too often stem from: Inexperienced developers who don't know how to do it the easy way - inefficiencies due to huge workarounds that have hidden costs.

E.g.: Not using builtin methods but writing buggy workarounds. Or even very basic stuff like: Using expensive functions within loops instead of hoisting those outside of it.

I wouldn't even call those "optimizations".

Re:Do you know how much your computer can do in a second? by crdoconnor on Sunday October 25, 2015 @10:08AM (#10446894)
>So your opinion is "If it's slow it's okay, because it's safer than optimizing?".

No. My opinion is that if it's slow you need to check to see if it's actually a problem for the users first before optimizing. Unless...

>And that's where your actual noticable inefficiencies far too often stem from: Inexperienced developers who don't know how to do it the easy way

I already said this below:

>Cleaning up dirty code that incidentally causes performance improvements is fine

Re:Do you know how much your computer can do in a second? by toothbrush on Sunday October 25, 2015 @10:23AM (#10446921)
> No. My opinion is that if it's slow you need to check to see if it's actually a problem for the users first before optimizing.

Not only. Think of all these seconds of computing time, translated into watts, translated into coal or whatever pollution from electricity production, multiplied by the number of users your program has.

I think programmers should also consider the environment, even if it'd have more impact if everyone started by just not owning a car.

Re:Do you know how much your computer can do in a second? by scrollaway on Sunday October 25, 2015 @10:57AM (#10447014)
Unless we're talking about optimizing stuff that actually takes 100% of the CPU's or graphics card's power, it'd have more impact if just one person started not owning a car. Or even merely used it a bit less.

Appreciate the sentiment but it's not going to achieve anything. "Tut-tut" attitude is a lot less efficient than simply showing people why it's worth optimizing for their own sake. If it's worth optimizing at all, that is - GP's point is that it's not always worth it. Optimization has a cost. Development cost and maintenance cost. What's the point of making a program faster if nobody can ever really work on that piece of the code again?

By the way, the hour the programmer stays in the office overtime to optimize that code, using computers and lights and other machines, probably damages the environment more than your example before...

Re:Do you know how much your computer can do in a second? by toothbrush on Monday October 26, 2015 @07:02AM (#10450594)
> By the way, the hour the programmer stays in the office overtime to optimize that code, using computers and lights and other machines, probably damages the environment more than your example before...

What if we're talking about the file-copy API in some widely distributed operating system? That's going to be multiplied by millions and millions of people, and therefore, being an obtuse devil's advocate, i argue that indeed it would have an appreciable impact on the environment.

If, however, you're talking about some relatively infrequently used GUI element in an application which has merely a million users, then okay, indeed, go home and don't waste another hour of lights and computers at your office :).

Re:Do you know how much your computer can do in a second? by CydeWeys on Sunday October 25, 2015 @09:41AM (#10446843)
Nobody (hopefully!) is defending important library optimizations.

The kind of unnecessary optimizations I think about as being undesirable are when you spend a week's worth of engineering effort and go through a potentially risky data migration just in order to improve the performance of a command-line production environment management tool that is run once per few months, that only takes a few minutes to run anyway, and whose data is cached server-side by the application running it anyway.

Actual example from my software engineering career.

But for library code, that potentially thousands or even millions of systems in production worldwide are going to be using? Hell yes. That is worth the time to improve. And kudos to you on improving Node postgres performance. That's awesome.

Re:Do you know how much your computer can do in a second? by gaius on Sunday October 25, 2015 @05:30AM (#10446453)
Not 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.

Re:Do you know how much your computer can do in a second? by crdoconnor on Sunday October 25, 2015 @05:51AM (#10446484)
>Not one-tenth of the problem as people who wrap trivial computations in "enterprise" crapware and use 100x the CPU they really need

I still doubt that the CPU/power/cooling cost of having systems infested with hacky enterprise garbage is its biggest drawback.

That crap also causes expensive bugs and huge maintenance costs (e.g. relatively simple programs that require a team of 12 programmers a month to implement the simplest feature).

Re:Do you know how much your computer can do in a second? by larsmak on Sunday October 25, 2015 @05:38AM (#10446469)
Yes, 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.
Re:Do you know how much your computer can do in a second? by gaius on Sunday October 25, 2015 @06:11AM (#10446515)
... Which they did perfectly well in the 60s on a mainframe. Why does it take - conservatively estimating - a million times more CPU cycles now?
Re:Do you know how much your computer can do in a second? by praseodym on Sunday October 25, 2015 @11:12AM (#10447070)
They'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/ [2] https://en.wikipedia.org/wiki/CICS - yes, "Initial release: 1968; 47 years ago"

Re:Do you know how much your computer can do in a second? by coldtea on Sunday October 25, 2015 @09:32AM (#10446823)
Most banks and payment systems have old, reliable codebases, a lot of them even in COBOL. Banks don't play with those systems often, and they don't use monstrocities like J2EE for them.

It's the other kinds of enterprise systems that are crap and deserve no respect. Intranet apps in big corporations, the BS systems that always mess up your bills in services companies, slow as molasses web portals for big enterprises and organisations etc, ERP and CRM apps...

Re:Do you know how much your computer can do in a second? by c22 on Sunday October 25, 2015 @02:30PM (#10447792)
I've worked on an old COBOL codebase and "reliable" is not a word I associate with it.
Re:Do you know how much your computer can do in a second? by gaius on Monday October 26, 2015 @03:58AM (#10450030)
It is front page news when it goes wrong, tho', look at NatWest. So objectively speaking, it is pretty reliable.
Re:Do you know how much your computer can do in a second? by panic on Sunday October 25, 2015 @05:33AM (#10446458)
The grandparent post isn't talking about over-optimizing. You shouldn't have to add disgusting hacks to complete a trivial operation in less than a second.
Re:Do you know how much your computer can do in a second? by netcan on Sunday October 25, 2015 @05:40AM (#10446472)
Yet both the efficiency the great-grandparent is talking about and the efficiency hacks that the grandparent is talking about exist.

This is evidence of how hard it is to do everything right, especially if you have more than one axis along which you are trying to be right.

Re:Do you know how much your computer can do in a second? by crdoconnor on Sunday October 25, 2015 @05:59AM (#10446494)
>The grandparent post isn't talking about over-optimizing.

Nonetheless, warning bells go off inside my head whenever I hear that opinion expressed without the caveat "if it isn't a problem for the user, leave it the fuck alone".

>You shouldn't have to add disgusting hacks to complete a trivial operation in less than a second.

If a trivial operation takes more than a second that's almost always indicative of a bigger underlying problem of crappy code.

Cleaning up dirty code that incidentally causes performance improvements is fine, but changing code specifically to make performance improvements without improving its overall quality leads to a downward spiral of shit.

Re:Do you know how much your computer can do in a second? by velox_io on Tuesday October 27, 2015 @08:42AM (#10457586)
There 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-orie...

Re:Do you know how much your computer can do in a second? by rasz_pl on Sunday October 25, 2015 @11:49AM (#10447175)
LAME. 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