optimization

Finding head and tail events in SQL Server (Optimisation)

I have a table of events, I need to find all tail events of type 1 and all head events of type 1. So, for the set of events in this order [1, 1], 3, 1 ,4, 5, [1,1,1] the brackets denote head and tail events of type 1. This is much better illustrated in SQL: drop table #event go create table #event (group_id int, [date] datetime, [t...

Transaction level, nolock/readpast and concurrency

We have a system that is concurrently inserted a large amount of data from multiple stations while also exposing a data querying interface. The schema looks something like this (sorry about the poor formatting): [SyncTable] SyncID StationID MeasuringTime [DataTypeTable] TypeID TypeName [DataTable] SyncID TypeID DataC...

Performance metrics on specific routines: any best practices?

I'd like to gather metrics on specific routines of my code to see where I can best optimize. Let's take a simple example and say that I have a "Class" database with multiple "Students." Let's say the current code calls the database for every student instead of grabbing them all at once in a batch. I'd like to see how long each trip to th...

Oracle SQL Optimization: SQL Query taking very long time

SELECT DISTINCT 'LRS-TECH 1' || rpad(code,7) || rpad('APPTYPE',30) || rpad(licensing_no,30) || rpad(' ',300) AS RECORD FROM APPS WHERE L_code = '1000' AND licensing_no IS NOT NULL This seems to be the primary culprit in why I cannot export these records to a textfile in my development environment. Is there any way I can ge...

Why isn't MySQL using the index for this subquery?

I used to do this: SELECT layerID FROM layers WHERE ownerID = ? AND collectionID = ? Which would give me an array of layerID's, and then I'd loop and do this for each one: SELECT DATA FROM drawings WHERE layerID = ? And it all worked fine. So now I'm trying to do it in one step, so I try this: SELECT DATA , layerID FROM drawings W...

Does C# optimize the concatenation of string literals?

For instance, would the compiler know to translate string s = "test " + "this " + "function"; to string s = "test this function"; and thus avoid the performance hit with the string concatenation? ...

How to convert last 3 digits of number into 0

How to convert last 3 digits of number into 0 example 3444678 to 3444000 I can do like (int)(3444678/1000) * 1000= 3444000 But division and multiplication could be costly... Any other solution???? ...

Effects of branch prediction on performance?

When I'm writing some tight loop that needs to work fast I am often bothered by thoughts about how the processor branch prediction is going to behave. For instance I try my best to avoid having an if statement in the most inner loop, especially one with a result which is not somewhat uniform (say evaluates to true or false randomly). ...

Does VB.NET optimize the concatenation of string literals?

Similar to this question, but for VB.NET since I learned this is a language thing. For instance, would the compiler know to translate Dim s As String = "test " + "this " + "function" to Dim s As String = "test this function" and thus avoid the performance hit with the string concatenation? ...

What can I do to optimize my .NET Web sites and applications for 64-bit?

How can I take full advantage of 64-bit architecture in my .NET 2.0 Web Applications and Console/Forms Applications? ...

Is it better to use ob_get_contents() or $text .= 'test';

I have seen a lot of ob_get_clean() the last while. Typically I have done $test .= 'test' I'm wondering if one is faster and/or better than the other. Here is the code using ob_get_clean(): ob_start(); foreach($items as $item) { echo '<div>' . $item . '</div>'; } $test = ob_get_clean(); Here is the code using $test .= 'test': ...

MySQL True vs False optimization

Can someone explain to me why I'm seeing the following behavior: mysql> show index from history_historyentry; +----------------------+------------+------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name ...

Optimisation: use local files or databases for HTML

This follows on from this question where I was getting a few answers assuming I was using files for storing my HTML templates. Before recently I've always saved 'compiled' templates as html files in a directory (above the root). My templates usually have two types of variable - 'static' variables which are not replaced on every usage bu...

Finding the minimal coverage of an interval with subintervals

Suppose I have an interval (a,b), and a number of subintervals {(ai,bi)}i whose union is all of (a,b). Is there an efficient way to choose a minimal-cardinality subset of these subintervals which still covers (a,b)? ...

How important is to not load unused scripts in PHP?

On a site where 90% of the pages use the same libraries, should you just load the libraries all the time or only load them when needed? The other pages would be ajax or simple pages that don't have any real functionality. Also, should you only load the code when needed? If part way down a page you need a library, should you load it then...

How to improve performance of an Abstract Factory when all the time appears to be spent in memory allocation.

The application de-serializes a stream into dynamically allocated objects and then keeps base type pointers in a linked list (i.e. abstract factory). It's too slow. Profiling says all the time is spent in operator new. Notes: The application already uses a custom memory allocator that does pooling. The compiler is VC++ 6.0 and the co...

What is the fastest way to get the 4 least significant bits in a byte (C++)?

I'm talking about this: If we have the letter 'A' which is 77 in decimal and 4D in Hex. I am looking for the fastest way to get D. I thought about two ways: Given x is a byte. x << 4; x >> 4 x %= 16 Any other ways? Which one is faster? Thanks. ...

Fastest way to determine if an integer's square root is an integer

I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer). I've done it the easy way, by using the built-in Math.sqrt() function, but I'm wondering if there is a way to do it faster by restricting yourself to integer-only domain. Maintaining a lookup table is impratical (...

What optimizations today are going to be useless tomorrow?

I hope we all know by now that Premature optimization is the root of all evil. One side of that quote means by optimizing you are increasing complexity and complexity is evil. The other less known side is today's optimization might be meaningless tomorrow. What I mean is we used to think that, "Floating-point operations are slow, ther...

Optimization of Google App Engine Code

Google app engine tells me to optimize this code. Anybody any ideas what I could do? def index(request): user = users.get_current_user() return base.views.render('XXX.html', dict(profiles=Profile.gql("").fetch(limit=100), user=user)) And later in the template I do: {% for profile in profiles %} <a href="/p...