# Tagged Questions

Optimization is the process of improving an existing program to make it work more efficiently or/and using less resources.

499 views

### Efficient algorithm for Virtual Machine(VM) Consolidation in Cloud

PROBLEM: We have N physical machines(PMs) each with ram Ri, cpu Ci and a set of currently scheduled VMs each with ram requirement ri and ci respectively Moving(Migrating) any VM from one PM to ...
194 views

### Which is more expensive multiple conditional branches or multiple relational expression in a single condition?

Which is more expensive in terms of processing costs if ( x < 20 && z == "M") { // statements 3 } if ( x >= 20 && w && x <= 65) { // statements 1 } if( x &...
396 views

### How does an optimizing compiler react to a program with nested loops?

Say you have a bunch of nested loops. public void testMethod() { for(int i = 0; i<1203; i++){ //some computation for(int k=2; k<123; k++){ //...
330 views

### Why isn't Haskell able to optimize infinite lists?

Lets say you've got a list l = [0, 2..] and you want to get the nth number when n is pretty large, say n=123456789. So you call l !! 123456789. On my machine, this results in out of memory. So why ...
7k views

### Does C++ compiler remove/optimize useless parentheses?

Will the code int a = ((1 + 2) + 3); // Easy to read run slower than int a = 1 + 2 + 3; // (Barely) Not quite so easy to read or are modern compilers clever enough to remove/optimize "useless" ...
265 views

### Optimization ended up in casting an object at each method call

I've been doing some optimization for the following piece of code : public void DrawLine(int x1, int y1, int x2, int y2, int color) { _bitmap.DrawLineBresenham(x1, y1, x2, y2, color); } After ...
181 views

### Is retaining intermediate objects as member fields a good idea in this case?

I'm currently writing a series of classes in java that are meant to translate a regular expression (written with the formal definition, not language-specific shortcuts) into a deterministic finite ...
2k views

### Is there a performance difference between ++x over x++? [duplicate]

Is there a performance difference between using ++x over x++ increment operators? I've see developers use ++x in loops where I would normally write x++ out of habit. For example; for(int x=0; x &...
212 views

### Is it fine to reuse a class instance?

I ask in terms of high cost classes, with a particle engine as an example. I read somewhere that an instance of a class with a high cost to initialize, like a particle manager, should have its state ...
72 views

### Trying to “combine” similar objects without doing a bazillion comparisons

In this database I have "accesses" - each access can have any number (usually less than 4, sometimes as many as 15) attributes. I also have "tickets" where N users are requesting M accesses, so I've ...
80 views

### Performance consideration and code reduction for Templates

I'm trying to decide if this might be a good idea to help reduce the size of some of my xaml resource dictionaries on a large project. Except I'm concerned about any potential performance issues going ...
485 views

### Difference between Optimization and Scalability?

If I quote a paragraph from Wikipedia about Optimization: In computer science, program optimization or software optimization is the process of modifying a software system to make some aspect of ...
388 views

### Implementing bussiness logic with a large number of business rules and processes

We are currently working on a project that heavily relies on a database. Among many tables the main focus is on table "data" which is linked to another table "data_type" as many-to-one, which is then ...
399 views

### Mixing declarative & imperative code (Implicit 'unit tests' ?) [closed]

Well I'm no expert, but as a student, I'm curious about languages and their design patterns / goals. I'd like to know, whether there are any points I miss in the following examples, and why ...
607 views

### modelling a restaurant availability search

I am looking into finding an efficient way which can scale up to thousands of restaurants, for doing a reservation search. Ideally, it would be efficient to answer queries like find a restaurant ...
161 views

### Measuring “novelty” of data

I have a heuristic in mind that should allow me to "score" data based on "novelty" that I would like to work in real-ish time. In this case, I mean novelty in the sense that the data source is ...
366 views

### Next power of 2 for a number (in search for better “bit-twiddling” way)

I just wonder if there exists better (i.e. faster?) way to get the next power of 2 for a given number than the following one (maybe some better sort of "bit-twiddling" hack is possible?) ... static ...
13k views

### How do I traverse a tree without using recursion?

I have a very large in memory node tree and need to traverse the tree. Passing the returned values of each child node to their parent node. This has to be done until all the nodes have their data ...
1k views

### Unique and primary keys on a database (mysql)

I'm having quite some doubts here... If I have a table related to username/password login how can I assure there won't be any more matches of the same username and password in the same table using sql?...
2k views

### Algorithm for fast tag search

The problem is the following. There's a set of simple entities E, each one having a set of tags T attached. Each entity might have an arbitrary number of tags. Total number of entities is near 100 ...
720 views

### Multi regex matching — what to do to optimize it?

I have multiple regexes matching an input in greedy-first mode. All regexes are already compiled and I don't see what I can do more to speed-up things. I mean using tools coming with .Net framework. ...
318 views

### Compiler doesn't inline anything?

I've rolled my own SIMD-accelerated math library. It's gotten pretty complete, so naturally I went to conduct speed tests and optimize it. Btw this isn't premature optimization, the lib is actually ...
232 views

### Understanding velocity update in Binary Particle Swarm Optimization

I am wondering how to interpret the velocity update in a Binary Particle Swarm Optimization (PSO). To recap the velocity update : V(t+1) = V(t) + c1 * r1 * (XlocalBest - X(t)) + c2 * ...
2k views

### Ordering if conditions for efficiency and clean code [closed]

This is purely a design question and the example is simple to illustrate what I am asking and there are too many permutations of more complex code to provide examples that would cover the topic. I am ...
244 views

### What are some efficient ways to set up my environment when working on a remote site?

Hello fellow Programmers, I am still a relatively new programmer and have recently gotten my first on-campus programming position. I am the sole dev responsible for 8 domains as well as 3 small sized ...
181 views

### Optimising news fetching

I have a web scraper for scraping news from different sources in wp7. My current appraoch for doing this is: load newspapers information from xml file. go to the specified sections and fetch the ...
490 views

### How small is the footprint of a small C compiler?

This week I could optimize using a reduced C library that allowed a drastic shrinkage in code size - from about 60 K to about 6 K and then we could load the code in the 8 K on-chip memory of an FPGA (...
672 views

### Optimizing code generation for expressions in a compiler

I don't know if this question has a simple answer or not, but I just have to ask. I'm reading this tutorial (I don't know if this is a well-known series, but it's name is 'Let's build a compiler!' by ...
449 views

### Larger Code is Still Faster

When compiling C code with gcc, there are compiler optimizations, some that limit code size and others create fast code. From the -S flag, I see that the -O2/03 generates more assembly than the -Os ...
7k views

### How to find bottlenecks in an application? [duplicate]

I'm building an application with lots of components, a lot of which are third-party so I only know what I can get from their documentation. From time to time, by pure luck, I find out one of these ...
1k views

### Does setting a function public affect the C# compiler's ability to inline the function as an optimization?

This could be either for the .NET or Mono compilers. I know that under certain conditions the compiler can inline functions (e.g. small, single call site, etc.) as an optimization. However, if the ...
150 views

### Optimization of time-varying parameters

I need to find an optimal set of "n" parameter values that minimize an objective function (a 2-hr simulation of a system). I have looked at genetic algorithm and simulated annealing methods, but was ...
328 views

### Which if statement requires less computation?

I have if (!b && c || a && c) //do action a else //... Due to some internal relationship between a, b, and c. !b && c || a && c is proved to be equivalent to (! ...
313 views

### Algorithm to arrange objects so that the total length of edges between them is minimized?

We are given a list of edges between a set of N vertices. There are atmost three edges joining a vertex. We have to arrange all the vertices on a straight line with the positions numbered from 1 to N ...
2k views

### What is the exact syntax of inline?

CASE 1 (Definition and declaration in same source file) Suppose both my prototype and definition of global function is in .cpp file. Where should I write inline keyword to make compiler know? In ...
781 views

### What are some algorithms that can assist with reservation time scheduling?

Here's the gist of the problem: There are multiple service providers who each have their own schedules of availability. There are multiple customers who seek their services. Customers need to be able ...
319 views

### Efficient way of evaluating an array of strings then add to an array in Ruby

I am looking for an efficient way of evaluating an array of strings against a series of rules and then adding them to another array. For example I have an array of strings: something a 1234 #gohere ...
2k views

### Benefits of setting PHP memory_limit to lower value for specific PHP script?

I need to execute just few lines of PHP code on every single page of my website. This PHP code does not require more than 4MB memory. That is why i want to allocate just 4MB memory to all pages by ...
278 views

### Premature optimization in deciding how to optimize?

We have a class that has been properly identified for optimization. We've done the profiling and testing, and it's a problem. Now we have two possible approaches for optimizing this class: There is ...
448 views

### Are there algorithims for polling optimization?

I have a web-application with an async HTTP backend, which gets called by the client by AJAX requests. The client has to start a job and then polls for the result. I started with a simple 150ms ...
955 views

### Sum of divisors of numbers of the range ~ 10^6

I was trying to find the sum of divisors of numbers upto 106. The test cases are like of the order of 105. I have done some pre processing like int divisors(int num) { int sum=0; for(int i=1;...
577 views

### When to start thinking about scalability? [closed]

I'm having a funny but also terrible problem. I'm about to launch a new (iPhone) app. It's a turn-based multiplayer game running on my own custom backend. But I'm afraid to launch. For some reason, I ...
666 views

### Python — Time complexity of built-in functions versus manually-built functions in finite fields

Generally, I'm wondering about the advantages versus disadvantages of using the built-in arithmetic functions versus rolling your own in Python. Specifically, I'm taking in GF(2) finite field ...
611 views

### Structuring Access Control In Hierarchical Object Graph

I have a Folder entity that can be Moderated by users. Folders can contain other folders. So I may have a structure like this: Folder 1 Folder 2 Folder 3 Folder 4 I have to ...
2k views

### Are unused CSS rules so costly that they must be removed?

I have been reading various Web application optimizing articles and many of them suggest to remove unused CSS rules. Currently, I have a page which has jQueryUI css, Bootstrap CSS, Datatables CSS and ...
401 views

### Change of the complexity class through compiler optimization?

I am looking for an example where an algorithm is apparently changing its complexity class due to compiler and/or processor optimization strategies.
139 views

### Use functions inside a loop declaration

What's the best practice? This : for (\$i = 0; \$i < count(\$array); \$i++) { //stuff } Or, what I usually do : \$count = count(\$array); for(\$i = 0; \$i < \$count; \$i++) { //stuff } Is it the ...
126 views

### Find common functionalities or functions between 2 programs

I've been facing a problem recently, in which I want to optimize two programs. For that, I wanted to create some kind of "Common Interface" which I could reuse between my two programs. However, the ...