Hot answers tagged

17

What semantic features of Python (and other dynamic languages) contribute to its slowness? None. Performance of language implementations is a function of money, resources, and PhD theses, not language features. Self is much more dynamic than Smalltalk and slightly more dynamic than Python, Ruby, ECMAScript, or Lua, and it had a VM that outperformed all ...


7

While Python's current implementation (which lacks a lot of the optimisations performed by other dynamic languages, e.g. modern Javascript implementations and, as you point out, Lua) is a source of most of its problems, it does have some semantic issues that would make it difficult for an implementation to compete with other languages, at least in certain ...


6

The scheduling mechanism you have described is Fixed-priority pre-emptive scheduling. If you know there is a possibility the max priority queue is always full, then you are using the wrong mechanism, because of starvation as you described. You could prevent starvation by using a different scheduler. For instance, you can say that you process at most f(...


5

Measure first instead of making assumptions. The sequence of 30 tests "if (possibleSolution)" is something that a good compiler should be able to optimise away. At the first "if (possibleSolution)" a good compiler would generate code that doesn't only skip one call, but figures out immediately that the second, third, and so on if are also going to fail, so ...


4

Instantiating and collecting small, short-lived, temporary objects, is perfectly fine. It is what modern garbage collectors are good at. Modern (generational) garbage collectors are built on a couple of assumptions: most objects die young, most objects are small, most objects don't escape, most objects are immutable, older objects don't contain references ...


3

Basically you're making priority a function of two variables, like pricePaid*A + waitingTime*B. That's a perfectly sensible strategy. Suppose you're selling tickets, and the price people pay puts them into one of the queues - high, medium, low. You could look at that as a single ordered priority queue, where the priority is high, medium, or low. Within each ...


2

Replace If(pass) pass=testN(c,d); With If(!testN(c,d)) {break;} This way you get to a new cycle right away.


2

The first thing to realize is that the situation you describe (some items are 'never' processed) can only arise if you simply don't have the capacity to handle the volume of requests. If you have the capacity to handle the expected volume of requests over a given time period, you will be able to handle all the requests. This is a tautology. Changing the ...


2

Eugene Philipov ran a benchmark on multiple INSERTs in one query and found out that they are really faster than running many sequential inserts after each other. This really did not come as a surprise because INSERT is a very simple operation. For updates the reason why you'd be taking multiple trips to a database is because the code is simply easier to ...


1

This is what non-functional requirements of performance are for. The notion of fast enough has nothing technical per se. It depends on user perception of your product, and should be translated through the requirements. This is the only objective way for you to tell whether your actual implementation is fast enough or not. If you don't have those ...


1

You have forgotten the most basic question: Is the speed satisfactory for the use case? If the answer is "yes" -> don't profile If no, you might look at your table. But honestly, it looks not terribly useful, because almost all time is spend in OBSparser.py:48(parse), which takes a LONG time. I would suggest you refactor that method into several ...


1

You could use java 8's Streams, which will do short-circuiting under the hood for you. To get around some boxing/unboxing you can define this internal interface : private interface SolutionTest { boolean test(int a, int b); } With this in place you can introduce these helper methods : private boolean isPossibleSolution(int c, int d) { return ...


1

I'm not sure if this is what you mean, but you can do such a thing with a labeled break/continue (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html): main: for (int d = 0; d <= max; d++) { subMain: for (int c = 0; c < d; c++) { boolean possibleSolution = test1(c,d); if(!possibleSolution) continue main;...


1

Based on your question break; will NOT work for you. You want to skip all further steps in this cycle, do c++ and go for a new round. This is done using continue. Break will end inner cycle do d++ and start inner cycle from 0.



Only top voted, non community-wiki answers of a minimum length are eligible