optimization

optimization of access to members in c++

I'm running into an inconsistent optimization behavior with different compilers for the following code: class tester { public: tester(int* arr_, int sz_) : arr(arr_), sz(sz_) {} int doadd() { sm = 0; for (int n = 0; n < 1000; ++n) { for (int i = 0; i < sz; ++i) { ...

MySQL query optimization is driving me nuts! Almost same, but horribly different

I have the following two queries (*), which only differ in the field being restricted in the WHERE clause (name1 vs name2): SELECT A.third_id, COUNT(DISTINCT B.fourth_id) AS num FROM first A JOIN second B ON A.third_id = B.third_id WHERE A.name1 LIKE 'term%' SELECT A.third_id, COUNT(DISTINCT B.fourth_id) AS num FROM first A JOIN second...

Faster, more efficient JPEG conversion and compression on the iPhone

I'm grabbing frame images from the iPhone's camera at a rate of 25fps using a resolution of 192 x 144 and a 420v, BGRA format. I'm converting the CVImageBufferRefs into UIImages and then calling UIImageJPEGRepresenation(image, compressionQuality) to get a compressed JPEG version of the image. Using the Time Profiler in Instruments, I c...

How to optimize and pre-compile this LINQ expression?

Given the following input against 60% toleration "STACKOVERflow is a quesTions and ANSwers weBSITE" I expect the following output // Extra spaces just to show %s // 69% 50% 100% 22%! 33% 42% 14% "Stackoverflow Is A QuesTions And ANSwers Website" Questions and Answers have uppercase characters but they rep...

May a pointer ever point to a cpu register?

I'm wondering if a pointer may point to a cpu register since in the case it may not, using reference instead of pointer where possible would give compiler opportunity to do some optimizations because the referenced object may reside in some register but an object pointed to by a pointer may not. ...

Optimizing g++ when indexing an array with an injective function

I have a for loop where each step i, it processes an array element p[f(i)], where f(i) is an injective (one-to-one) map from 1...n to 1...m (m > n). So there is no data coupling in the loop and all compiler optimization techniques such as pipelining can be used. But how can I inform g++ of the injectivity of f(i)? Or do I even need to (c...

Can loop unrolling or duff's help this situation?

I am using this bit of code in order to reformat some large ajax responseText into good binary data. It works, albeit slow. The data that I am working with can be as large as 8-10 megs. I need to get this code to be absolutely efficient. How would loop unrolling or Duff's device be applied to this code while still keeping my binary dat...

Minimum area triangle from a given set of points

Given a set of n points, can we find three points that describe a triangle with minimum area in O(n^2)? If yes, how, and if not, can we do better than O(n^3)? I have found some papers that state that this problem is at least as hard as the problem that asks to find three collinear points (a triangle with area 0). These papers describe a...

How to use a look up table in MATLAB

I need to perform an exponential operation of two parameters (one set: t, and the other comes from the arrays) on a set of 2D arrays (a 3D Matrix if you want). f(t,x) = exp(t-x) And then I need to add the result of every value in the 3rd dimension. Because it takes too much time using bsxfun to perform the entire operation I was thi...

Memory consuption code optimization, a garbage collector question

In my WPF-application I call new windows in the following way: _newWin = new WinWorkers_AddWorker(); _newWin.WindowState = this.WindowState; _newWin.Show(); Where _newWin is a private Window object. My question is should I assign a null value to _newWin after I call _newWin.Show()? Will this decrease memory consumption, because garb...

How can I optimize this wordpress mysql query?

I have a mysql query which is really bogging down my VPS. Its doing a filesort according to explain extended. I usually optimize queries on my own but this one i'm not sure I know how. SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_posts.*,MAX((1.00 * (MATCH(wp_search_post.post_content) AGAINST ('test' IN BOOLEAN MODE))) + (2.00 * (MATCH(wp_se...

Compare Round Robin and Multilevel Feedback Queue in terms of waiting time, response time, turnaround time

I want to make a comparison between RR and MLFQ in terms of waiting time, response time, turnaround time in 3 cases: a) More CPU-bounded jobs than I/O jobs b) More I/O-bounded jobs than CPU bounded jobs c) When only a few jobs need to schedule. Could you help me to clarify or give me some sources for reference. Thanks ...

JavaScript/jQuery optimization

I have just finished my new portfolio site visible at http://www.pepkarsten.com/artdirection. It is a single page that loads images (with loader animation, preloading and keyboard shortcuts). Here is the JavaScript code (using jQuery). How can it be optimized? $(document).ready(function() { function page(slide,width,height,color) ...

Good Reading on Rails Database Optimizations: Caching ids in column, demormalization?

I'm looking for some (more than intro-level) database optimizations, not just for Rails but for SQL in general. In Rails, how/when do you start using these? cache_counter caching ids in a table (user has_many roles, so the user table gets a role_ids serialized column, since every request requires fetching the roles). Are these types...

Weighted n-coloring problem algorithms

I have 100 vertices and a function f(x,y) that computes the weight of the edge between vertex x and vertex y. f is not particularly expensive, so I could generate an indexed adjacency list with weights, if necessary. What are some efficient, tractable methods for optimizing the n-coloring of these vertices by minimizing or maximizing t...

Performance vs Correctness/Preference?

typedef unsigned char uChar; typedef signed char sChar; typedef unsigned short uShort; typedef signed short sShort; typedef unsigned int uInt; typedef signed int sInt; typedef unsigned long uLong; typedef signed long sLong; I have a list of typedefs so when I define variables, I can be exact. For instance, if I only need the numbers...

Do global variables mean faster code?

I read recently, in an article on game programming written in 1996, that using global variables is faster than passing parameters. Was this ever true, and if so, is this still true today? ...

Is there an advantage on the iPhone to breaking up an operation into multiple threads?

I have a method in my iPhone app that is very repetitive (called over and over and over sequentially). The method is quite bulky and takes about one second to complete. My question is this: If I was to muti-thread it to run, say 5 method calls on different threads simultaneously, would that be any faster than running 5 calls one after ...

C "Static" Optimization

Hello. I'm reading the book about optimization teckniks. There is not much description or advices in example though. Here's the thing: int agag(int a) { static int dfdfdf = 0; static int prev_resilt = 0; if (dfdfdf == a) return prev_result; dfdfdf = a; a = SomeCalcs(); prev_result = a; return a; } The key thing is: i...

Addressing Scalability,Performance and Optimization issues in RMI Application?

Dear Experts, my problem is: this design is working fine for one ball but i m unable to get it work for multiple balls, i have basically problem in replacing the "this" keyword in updateClients (). i thought i need to do something like this but i m failed: System.out.println("in ballimpl" + j.size()); for (ICallback aClie...