optimization

How can I analyze and optimize my sql query

SELECT K.euclidNo,K.KlinikAdi,k.kisaAdi, (SELECT COUNT(1) FROM Seanslar AS S INNER JOIN Faturalar AS F ON F.fatura_id = S.refFatura_id INNER JOIN BasilmisFaturalar AS BF ON BF.basilmisFatura_id = F.refBasilmisFatura_id WHERE MONTH(S.tarihi)<MONTH(F.faturaTarihi) AND S.refKlinik_id = K.klinik_id AND S.durumuVT = 1 AND F.faturaTArihi BETW...

Cocoa/Objective-C: how much optimization should I do myself?

I recently found myself writing a piece of code that executed a Core Data fetch, then allocated two mutable arrays with the initial capacity being equal to the number of results returned from the fetch: // Have some existing context, request, and error objects NSArray *results = [context executeFetchRequest:request error: NSMutableArra...

Code optimization

If I have a big structure(having lot of member variables). This structure pointer is passed to many functions in my code. Some member variables of this structure are used vary often, in almost all functions. If I put those frequently used member variables at the beginning in the structure declaration, will it optmize the code for MCP...

Is this a bug in MS CL's global optimization (/Og)?

Hi guys, Here is a very simplified program which reproduces the issue I faced in the real application: #include "stdlib.h" typedef unsigned short int shft; struct xptr { int layer; void * addr; xptr() : layer(0), addr(NULL) {} xptr(int _layer, void *_addr) : layer(_layer), addr(_addr) {} xptr(const xptr& x) { la...

Fast way to pick randomly from a set, with each entry picked only once?

I'm working on a program to solve the n queens problem (the problem of putting n chess queens on an n x n chessboard such that none of them is able to capture any other using the standard chess queen's moves). I am using a heuristic algorithm, and it starts by placing one queen in each row and picking a column randomly out of the column...

Source Clean-up Question

I have source that has been around for 10 years old in C++. It works on OS X, Linux and Windows well. It is a static Library of API calls other developers might need to use. Over time, previous programmers have sort of not kept it tidy. So my question: There are several headers that most sources use. I could put them all in a single h...

Fast Saturate and shift two Halfwords in ARM asm

I have two signed 16-bit values in a 32-bit word, and I need to shift them right (divide) on constant value (it can be from 1 to 6) and saturate to byte (0..0xFF). For example, 0x FFE1 00AA with shift=5 must become 0x 0000 0005; 0x 2345 1234 must become 0x 00FF 0091 I'm trying to saturate the values simultaneously, something like th...

PHP IF Statement Evaluation & Server Overhead

I'm curious what the impact on the server is when PHP if statements are evaluated, i.e. memory consumption and CPU usage and if this could become a major issue as traffic grows? For example, if I use a lot of PHP IF statements in the theme for each post summary on a WordPress blog, is this going to require a great deal more server resou...

Faster way to find duplicate SQL query

I have a query to get duplicate data with some extra condition but I feel that it is not fast enough. Any solution to make this query faster? v_listing contains big information SELECT DISTINCT code, name, comm, address, area FROM v_listing t1 WHERE EXISTS (SELECT NULL FROM v_listing t2 WHERE t1.comm = t2...

how fast is python's slice

In order to save space and the complexity of having to maintain the consistency of data between different sources, I'm considering storing start/end indices for some substrings instead of storing the substrings themselves. The trick is that if I do so, it's possible I'll be creating slices ALL the time. Is this something to be avoided?...

Help speed up this algorithm? Sieve of Eratosthenes

I've written an algorithm that I believe to be correct for computing prime numbers up to n with the Sieve of Eratosthenes. Unfortunately, this program hangs on really large values of n (try 10 million). Here is what I've written... Protected Function Eratosthenes(ByVal n As Integer) As String Dim maxValue As Integer = Math.Sqrt(n)...

How can I refactor these functions to foster code-reuse?

I wrote these helper functions a few weeks ago and I feel like I'm not taking advantage of some C# language features that would keep me from writing these same loops again for other similar helpers. Can anyone suggest what I'm missing? public static IList<string> GetListOfLinesThatContainTextFromList( Stream aTextStream, IList<...

Optimize code so that it executes faster.

Hi, How can I optimize the following code so that it executes faster: static void Main(string[] args) { String a = "Hello "; String b = " World! "; for (int i=0; i<20000; i++) { a = a + b; } Console.WriteLine(a); } ...

Download when idle/low network utilization

I have an update service that needs to pull data down from remote, however like Microsoft's BITS I'd like to do this when the user is idle and/or when their network utilisation is low so as to not impact on their experience. What do I need to do or look at? Can anyone point me in the right direction on where to start with this and get t...

prime generator optimization

I'm starting out my expedition into Project Euler. And as many others I've figured I need to make a prime number generator. Problem is: PHP doesn't like big numbers. If I use the standard Sieve of Eratosthenes function, and set the limit to 2 million, it will crash. It doesn't like creating arrays of that size. Understandable. So now I'...

db optimization: computing rank

This question asks how to select a user's rank by his id. id name points 1 john 4635 3 tom 7364 4 bob 234 6 harry 9857 The accepted answer is SELECT uo.*, ( SELECT COUNT(*) FROM users ui WHERE (ui.points, ui.id) >= (uo.points, uo.id) ) AS ran...

Is it better to use Bitmap or EncodedImage in BlackBerry?

In BlackBerry, is it better to use the Bitmap class or EncodedImage in terms of memory usage and performance? Are there any specific tips on using these classes? ...

basic operations cpu time cost

Hi! I was wondering, how to optimize loops for systems with very limited resources. Let's say, if we have a basic for loop, like ( written in javascript): for(var i = someArr.length - 1; i > -1; i--) { someArr[i] } I honestly don't know, isn't != cheaper than > ? I would be grateful for any resources covering computing cost in con...

Compile and optimize for different target architectures

Summary: I want to take advantage of compiler optimizations and processor instruction sets, but still have a portable application (running on different processors). Normally I could indeed compile 5 times and let the user choose the right one to run. My question is: how can I can automate this, so that the processor is detected at runt...

Is it necessary to cache common operations for -drawRect: on the iPhone?

This is a rather simple example and probably wouldn't make much of a difference anyway, but say I have this drawing code in a view to draw a gradient: @interface SomeView : UIView @end @implementation SomeView - (void)drawRect:(CGRect)rect { const CGContextRef ctx = UIGraphicsGetCurrentContext(); // Set fill color to white ...