optimization

What's optimal? UNION vs WHERE IN (str1, str2, str3)

I'm writing a program that sends an email out at a client's specific local time. I have a .NET method that takes a timezone & time and destination timezone and returns the time in that timezone. So my method is to select every distinct timezone in the database, check if it is the correct time using the method, then select every client ou...

Getting all types that implement an interface with C# 3.5

How can I do what's in the title, with the minimum amount of code, using whatever c# 3.5 syntax (I'm guessing lambda expressions would fit, but I still don't understand them fully)? In short, I want to iterate through all types that implement a particular interface. Edit: I wasn't clear. Let me re-phrase my question: How can I, using r...

Optimizing for low bandwidth

I am charged with designing a web application that displays very large geographical data. And one of the requirements is that it should be optimized so the PC still on dial-ups common in the suburbs of my country could use it as well. Now I am permitted to use Flash and/or Silverlight if that will help with the limited development time ...

Table Scan vs. Add Index - which is quicker?

I have a table with many millions of rows. I need to find all the rows with a specific column value. That column is not in an index, so a table scan results. But would it be quicker to add an index with the column at the head (prime key following), do the query, then drop the index? I can't add an index permanently as the user is nomin...

Which, if any, C++ compilers do tail-recursion optimization?

It seems to me that it would work perfectly well to do tail-recursion optimization in both C and C++, yet while debugging I never seem to see a frame stack that indicates this optimization. That is kind of good, because the stack tells me how deep the recursion is. However, the optimization would be kind of nice as well. Do any C++ comp...

SQL Server - Does column order matter?

In terms of performance and optimizations: When constructing a table in SQL Server, does it matter what order I put the columns in? Does it matter if my primary key is the first column? When constructing a multi-field index, does it matter if the columns are adjacent? Using ALTER TABLE syntax, is it possible to specify in what position...

What is the most efficient way to keep track of a specific character's index in a string?

Take the following string as an example: "The quick brown fox" Right now the q in quick is at index 4 of the string (starting at 0) and the f in fox is at index 16. Now lets say the user enters some more text into this string. "The very quick dark brown fox" Now the q is at index 9 and the f is at index 26. What is the most effi...

PostgreSQL perfomance monitoring tool

I'm setting up an web application with a FreeBSD PostgreSQL back-end. I'm looking for some database performance optimization tool/technique. Does someone know one? ...

Pinning pointer arrays in memory

I'm currently working on a ray-tracer in C# as a hobby project. I'm trying to achieve a decent rendering speed by implementing some tricks from a c++ implementation and have run into a spot of trouble. The objects in the scenes which the ray-tracer renders are stored in a KdTree structure and the tree's nodes are, in turn, stored in an ...

How do I strip the fluff out of a third party library?

It may not be best practice but are there ways of removing unsused classes from a third party's jar files. Something that looks at the way in which my classes are using the library and does some kind of coverage analysis, then spits out another jar with all of the untouched classes removed. Obviously there are issues with this. Specif...

Optimizing a LINQ to SQL query.

I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount) { DatabaseDataContext db = new DatabaseDataContext(); return (from o in db.Orders orderby o.CreatedDate descending select o) .Skip(pageIndex * recordCount) .Take(recordCount) .ToList(); } I need to print the infor...

Why are SQL aggregate functions so much slower than Python and Java (or Poor Man's OLAP)

I need a real DBA's opinion. Postgres 8.3 takes 200 ms to execute this query on my Macbook Pro while Java and Python perform the same calculation in under 20 ms (350,000 rows): SELECT count(id), avg(a), avg(b), avg(c), avg(d) FROM tuples; Is this normal behaviour when using a SQL database? The schema (the table holds responses to a s...

What is the real overhead of try/catch in C#?

So, I know that try/catch does add some overhead and therefore isn't a good way of controlling process flow, but where does this overhead come from and what is it's actual impact? ...

profile-guided optimization (C)

Anyone know this compiler feature? It seems GCC support that. How does it work? What is the potential gain? In which case it's good? Inner loops? (this question is specific, not about optimization in general, thanks) ...

Which compiles to faster code: "n * 3" or "n+(n*2)"?

Which compiles to faster code: "ans = n * 3" or "ans = n+(n*2)"? Assuming that n is either an int or a long, and it is is running on a modern Win32 Intel box. Would this be different if there was some dereferencing involved, that is, which of these would be faster? long a; long *pn; long ans; ... *pn = some_number; ans = ...

How do you normally set up your compiler's optimization settings?

Do you normally set your compiler to optimize for maximum speed or smallest code size? or do you manually configure individual optimization settings? Why? I notice most of the time people tend to just leave compiler optimization settings to their default state, which with visual c++ means max speed. I've always felt that the default set...

One big SQL Select statement or several small ones (Performance)?

Hi everyone, I'm building a PHP page with data sent from MySQL. Is it better to have 1 SELECT query with 4 table joins, or 4 small SELECT queries with no table join (I do select from an ID). Which is faster and what is the pro/con of each method? PS. I only need one row from each tables. ...

Optimize Windows Form Load Time

I have a Windows Form that takes quite a bit of time to load initially. However, each subsequent request to load the Form doesn't take as long. Is there a way to optimize a Form's load time? ...

Common memory optimization

What are the most common memory optimizations in csharp, dotnet 2.0. Wanted to see if there common things that people may not be doing by default in winform app ...

What steps should be necessary to optimize a poorly performing query?

I know this is a broad question, but I've inherited several poor performers and need to optimize them badly. I was wondering what are the most common steps involved to optimize. So, what steps do some of you guys take when faced with the same situation? Related Question: http://stackoverflow.com/questions/39331/what-generic-techniq...