optimization

Shortening a oft-used code segment for testing a return value in Python

Consider this Python segment: def someTestFunction(): if someTest: return value1 elif someOtherTest: return value2 elif yetSomeOtherTest: return value3 return None def SomeCallingFunction(): a = someTestFunction() if a != None: return a ... normal execution continues Now, t...

Code optimization bibles

Hello, What are the most highly regarded books on optimization / performance tuning of C/C++ code? ...

Should I include paginated results in my sitemap.xml?

I have listing pages that take a page argument on the url like the following: http://www.domain.com/foo/bar/?page=7 Should I just include the URL without params or should I list all pages in my sitemap.xml? EDIT Paginated content are listings, like an index. Therefore their content is also (in more detail) found in detail pages. But...

Fast circle collision detection

I'm trying to write a method that will calculate if two circles are overlapping. I've come up with the following and I'm just curious to know if there is anyway it could be optimised further. private static boolean isCollision(Point2D p1, float r1, Point2D p2, float r2) { float a,dx, dy; a = (r1+r2) * (r1+r2); dx = (float) (p1.getX()...

Best practices for optimizing LAMP sites for speed?

I did a cursory search and couldn't find this question and this could be viewed as a multi-part question so help me out in either case if I made a mistake. I want to know when building a typical site on the LAMP stack how do you optimize it for the best possible load times. I am picturing a typical DB-driven site. This is a high-level...

Need tips for optimizing SQL Query using a JOIN

The Query I'm writing runs fine when looking at the past few days, once I go over a week it crawls (~20min). I am joining 3 tables together. I was wondering what things I should look for to make this run faster. I don't really know what other information is needed for the post. EDIT: More info: db is Sybase 10. Query: SELECT a.id, a.da...

C# (.Net 2.0) Micro-Optimization Part 2: Finding Contiguous Groups within a grid.

I have a very simple function which takes in a matching bitfield, a grid, and a square. It used to use a delegate but I did a lot of recoding and ended up with a bitfield & operation to avoid the delegate while still being able to perform matching within reason. Basically, the challenge is to find all contiguous elements within a grid ...

Can this code be optimised?

I have some image processing code that loops through 2 multi-dimensional byte arrays (of the same size). It takes a value from the source array, performs a calculation on it and then stores the result in another array. int xSize = ResultImageData.GetLength(0); int ySize = ResultImageData.GetLength(1); for (int x = 0; x < xSize; x++) { ...

What optimizations are OK to do right away?

One of the most common mantras in computer science and programming is to never optimize prematurely, meaning that you should not optimize anything until a problem has been identified, since code readability/maintainability is likely to suffer. However, sometimes you might know that a particular way of doing things will perform poorly. W...

What are some good css and js minimizers for production code?

I'm looking for some applications or websites that minimize css and js files. Ideally, they could batch them all or if not, one at a time. Thanks! Brian ...

Another Linq2Sql Lazy loading question

Hi I have a read-only database, so I am turning off ObjectTracking (thus implicitly turning off DeferredLoading). I wish to do lazy loading and not use LoadWith<>. What is the simplest way to explicitly tell Linq to go and lazy fetch a relation just before I need the data itself. For example: a simple dbml If I have the following co...

Faster I/O in C

Hi, I have a problem which will take 1000000 lines of inputs like below from console. 0 1 23 4 5 1 3 5 2 56 12 2 3 33 5 ... ... I have used scanf, but it is very very slow. Is there anyway to get the input from console in a faster way? I could use read(), but I am not sure about the no of bytes in each line, so I can not as read() t...

What is the Speed Difference Between Database and Web Service Calls?

All things being equal, and in the most simple form, which is faster? 1.) A call to a web service method 2.) A call to a database For example, assume that you have a simple web service that just returns an integer that is calculated in X time. You also have a database that, when queried in th right way, also takes X time to calculate ...

room/timeslot schedule optimization

People can chose up to 5 of 25 lectures in advance. All these lectures are given on one day in five rooms at five time slots. Each (preferred) lecture a listener can attend to makes her a bit happier, each lecture he chose but can't attend to (because another preferred lecture is in the same time slot) makes him a bit unhappier. The list...

"Cannot convert to a SELECT statement" What does this mean

I'm trying to make our mySQL database run faster and I've analyzed our slow query log and the most common slow query is this: CREATE TABLE IF NOT EXISTS `wp_bad_behavior` ( `id` INT(11) NOT NULL auto_increment, `ip` TEXT NOT NULL, `date` DATETIME NOT NULL default '0000-00-00 00:00:00', `request_method` TEXT NOT NULL, `request_uri` ...

GCC/Make Build Time Optimizations

We have project which uses gcc and make files. Project also contains of one big subproject (SDK) and a lot of relatively small subprojects which use that SDK and some shared framework. We use precompiled headers, but that helps only for re-compilation to be faster. Is there any known techniques and tools to help with build-time optim...

Is a good idea to build in-memory indexes and circumvent the DB when operating intensively on a small subset?

I'm working on a program to automatically find optimal shift assignments, subject to lots of constraints. I'm using grails, i.e. the data about workers, shifts and assignments will be kept in a DBMS. For the optimization itself, I'll have to work very intensively on a small subset of the data (about 600 rows total from about 5 differen...

Efficient memory bandwidth use for streaming

I have an application that streams through 250 MB of data, applying a simple and fast neural-net threshold function to the data chunks (which are just 2 32-bit words each). Based on the result of the (very simple) compute, the chunk is unpredictably pushed into one of 64 bins. So it's one big stream in and 64 shorter (variable length) s...

How important is optimization?

I got into a bit of a debate yesterday with my boss about the proper role of optimization when building software. Essentially, his position was that optimization needs to be a primary concern during the entire process of development. My opinion is that you need to make the right algorithmic decisions during development, but you should n...

Does mod_wsgi (daemon) sites hand off content to apache to serve to the client?

I have Django deployed with mod_wsgi in daemon mode for apache2.2. So after Django churns out the content, does it hand off everything to apache from there to have it served in its optimised glory or is Django still somehow taxed in this serving step? ...