optimization

std::map insert or std::map find?

Assuming a map where you want to preserve existing entries. 20% of the time, the entry you are inserting is new data. Is there an advantage to doing std::map::find then std::map::insert using that returned iterator? Or is it quicker to attempt the insert and then act based on whether or not the iterator indicates the record was or was ...

Switch vs if-else

What's the best practice for switch vs if for a 30 unsigned enumerations where about 10 have an expected action (that presently is the same action). Performance and space need to be considered but are not critical. I've abstracted the snippet so don't hate me for the naming conventions :p // numError is an error enumeration type, with...

WCF - Overhead of throwing FaultExceptions within your service

I posted a question about using Messages versus Fault Exceptions to communicate business rules between services. I was under the impression it carried overhead to throw this exception over the wire, but considering it's just a message that get serialized and deserialized, they were in fact one and the same. But this got me thinking abo...

How to choose the max thread count for an HTTP servlet container?

I'm developing a restful Web service that runs as a servlet (using blocking IO) in Jetty. Figuring out the optimal setting for max threads seems hard. Is there a researched formula for deciding the max number of threads from some easily measurable characteristics of the rest of the setup? ...

SQL Server Management Studio – tips for improving the TSQL coding process

I used to work in a place where a common practice was to use Pair Programming. I remember how many small things we could learn from each other when working together on the code. Picking up new shortcuts, code snippets etc. with time significantly improved our efficiency of writing code. Since I started working with SQL Server I have bee...

Sorting a dict on __iter__

I am trying to sort a dict based on its key and return an iterator to the values from within an overridden iter method in a class. Is there a nicer and more efficient way of doing this than creating a new list, inserting into the list as I sort through the keys? ...

Explain Plan Cost vs Execution Time

Before, I have found the "Cost" in the execution plan to be a good indicator of relative execution time. Why is this case different? Am I a fool for thinking the execution plan has relevance? What specifically can I try to improve v_test performance? Thank you. Using Oracle 10g I have a simple query view defined below create or repl...

SQL Question - Possibly Cursor/Join related?

Here is my situation: Table one contains a set of data that uses an id for an unique identifier. This table has a one to many relationship with about 6 other tables such that. Given Table 1 with Id of 001: Table 2 might have 3 rows with foreign key: 001 Table 3 might have 12 rows with foreign key: 001 Table 4 might have 0 rows with fo...

What are the best SQL Server performance optimization techniques?

I've always taken the approach of first deploying the database with a minimal set of indexes and then adding/changing indexes as performance dictates. This approach works reasonably well. However, it still doesn't tell me where I could improve performance. It only tells me where performance is so bad that users complain about it. Curre...

Winform application profiling CPU usage / spikes . .

I have a winforms application that normally is at about 2-4% CPU. We are seeing some spikes up to 27% of CPU for limited number of times. What is the best profiling tool to determine what is actually causing this spike. We use dottrace but i dont see how to map that to exactly the CPU spikes? Appreciate the help ...

Fastest way to remove non-numeric characters from a VARCHAR in SQL Server

I'm writing an import utility that is using phone numbers as a unique key within the import. I need to check that the phone number does not already exist in my DB. The problem is that phone numbers in the DB could have things like dashes and parenthesis and possibly other things. I wrote a function to remove these things, the problem ...

MySQL: Advisable number of rows

Consider an indexed MySQL table with 7 columns, being constantly queried and written to. What is the advisable number of rows that this table should be allowed to contain before the performance would be improved by splitting the data off into other tables? ...

Speed up images in Tomcat 6

In tomcat 6 i have a servlet running openbluedragon, everything compiles and servers up quik, with the exception of images, they really lag significantly. Any suggestions optimization for image serving? Here is my server.xml: <Service name="Catalina"> <Connector port="8009" protocol="AJP/1.3" /> <Connector port="8080"...

likely/unlikely macros in the Linux kernel

I've been digging through some parts of the Linux kernel, and found calls like this: if (unlikely(fd < 0)) { /* Do something */ } or if (likely(!err)) { /* Do something */ } I've found the definition of them: #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) I know that they ...

GCC optimization flags for Intel Atom

I'm developing a performance critical application for Intel Atom processor. What are the best gcc optimization flags for this CPU? ...

What coding techniques do you use for optimising C programs?

Some years ago I was on a panel that was interviewing candidates for a relatively senior embedded C programmer position. One of the standard questions that I asked was about optimisation techniques. I was quite surprised that some of the candidates didn't have answers. So, in the interests of putting together a list for posterity - wha...

How to avoid the dangers of optimisation when designing for the unknown?

A two parter: 1) Say you're designing a new type of application and you're in the process of coming up with new algorithms to express the concepts and content -- does it make sense to attempt to actively not consider optimisation techniques at that stage, even if in the back of your mind you fear it might end up as O(N!) over millions o...

Running SQL Server on the Web Server

Is it good, bad, or indifferent to run SQL Server on your webserver? I'm using Server 2008 and SQL Server 2005, but I don't think that matters to this question. ...

What does "Optimize Code" option really do in Visual Studio?

Name of the option tells something but what Visual Studio/compiler really do and what are the real consequences? Edit: If you search google you can find this address, but that is not really I am looking for. I wonder the real things happening. For example why do the loops get less time, etc. ...

Optimize SQL query on large-ish table

First of all, this question regards MySQL 3.23.58, so be advised. I have 2 tables with the following definition: Table A: id INT (primary), customer_id INT, offlineid INT Table B: id INT (primary), name VARCHAR(255) Now, table A contains in the range of 65k+ records, while table B contains ~40 records. In addition to the 2 primary k...