running-time

Is the inequality operator faster than the equality operator?

I know this is a micro-optimization, so I ask out of pure curiosity. Logically, a microprocessor does not need to compare all the bits of both operands of an inequality operator in order to determine a "TRUE" result. Note, this is programming-related because it affects the execution speed of a program. ...

Most efficient way of converting String to Integer in java

There are many ways of converting a String to an Integer object. Which is the most efficient among the below: Integer.valueOf() Integer.parseInt() org.apache.commons.beanutils.converters.IntegerConverter My usecase needs to create wrapper Integer objects...meaning no primitive int...and the converted data is used for read-only. ...

Efficency of Comparisons in C++? ( abs(X)>1 vs abs(x) != 0)

I know- Premature optimization. But I've got code that's supposed to find out if a position is changed vs a cached position. Current code is: if(abs(newpos-oldpos) > 1){ ..... } Is it more efficient to use the following? if(abs(newpos-oldpos) != 0){ .... } Why or why not? I'm currently debating it my head which is more re...

Why does processing multiple individual targets take longer when Nant is directed to process them from a single target?

I have a nant build script that specifies the compilation of various Visual Studio solution files. <target name="compile.solution1" description="Compiles solution 1"> <msbuild project="${src.dir}\Solution1.sln" verbosity="${build.verbosity}"> <property name="Configuration" value="${build.config}" /> <property name="OutputPath" val...

Finding the nearest used index before a specified index in an array (Fast)

This question is related to http://stackoverflow.com/questions/1053242/array-of-pairs-of-3-bit-elements This array has 52 pairs (about 40 bytes), and I want to find the first pair before the specified one that has it's values different from 0 (used pair). The obvious solution would be to check each pair < than this one (scan from right t...

Why does this speed up my SQL query?

I learned a trick a while back from a DBA friend to speed up certain SQL queries. I remember him mentioning that it had something to do with how SQL Server compiles the query, and that the query path is forced to use the indexed value. Here is my original query (takes 20 seconds): select Part.Id as PartId, Location.Id as LocationId F...

Graph layout optimization in C#

I've got a list of objects that I need to organize as an aesthetic graph. My current approach involves IronPython and a genetic algorithm, but this takes way too long. I've been reading up on Graphviz, QuickGraph and Graph#, but I don't need the visualization part - I already have an app that will display the nodes given the x/y coordin...

Another question about premature optimization

Knuth said: We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil I’m curious how he came up with 97%. Could someone please share something about this? UPDATE: The problem is: This sentence is written in a research paper, how come a subjective statement get accepted in such...

Performing your own runtime analysis of your code in C#

I have written a large C# app with many methods in many classes. I'm trying to keep a log of what gets called and how often during my development. (I keep a record in a DB) Every method is padded with the following calls: void myMethod() { log(entering,args[]); log(exiting,args[]); } Since I want to do this for all my methods, is t...

How long does my code take to run?

How can I find out how much time my C# code takes to run? ...

How to change iPhone app language during runtime?

Is there a way to change the application language during runtime? So, after the change NSLocalizedString immediately returns the string for the new language. What I'm doing now is changing the language using the code below: - (void)onChangeLanguage: (id)sender { NSArray *lang = [NSArray arrayWithObjects:((InfoWhatever *)sender).langu...

Estimate Power Consumption Based on Running Time Analysis / Code Size

I've developed and tested a C program on my PC and now I want to give an estimate of the power consumption required for the program to do a single run. I've analysised the running time of the application and of invidiual function calls within the application and I know the code size both in assembly lines, but also raw C lines. How woul...

Running time of minimum spanning tree? ( Prim method )

I have written a code that solves MST using Prim method. I read that this kind of implementation(using priority queue) should have O(E + VlogV) = O(VlogV) where E is the number of edges and V number of Edges but when I look at my code it simply doesn't look that way.I would appreciate it if someone could clear this up for me. To me it s...

Best-case Running-time to solve an NP-Complete problem?

What is the fastest algorithm that exists up with to solve a particular NP-Complete problem? For example, a naive implementation of travelling salesman is O(n!), but with dynamic programming it can be done in O(n^2 * 2^n). Is there any perhaps "easier" NP-Complete problem that has a better running time? I'm curious about exact solutions...

Javascript run-time analysis

Hello, I've written a Javascript file, using jQuery, that I would like to perform run-time tests on. I've never done this before and was just curious on how to go about it. One site I visited suggested this as a measurement: var start = (new Date).getTime(); /* Run a test. */ var diff = (new Date).getTime() - start; This makes sense...

Record the Application session time using iPhone SDK?

I want to record the duration of Application executed in order to keep logs of activity of users. Should I use a global NSTimer to record the time? or is there any better method? Sample codes are appreciated. ...

What is total frequency count and running time (Big-O notation)?

I have the following code snippet: 1. for (i = 1; i < n; i++) 2. for (j = 1; j < i*i; j++) 3. if(j % i == 0) 4. for(k = 0; k < j;k++) 5. sum++; What is total frequency count and running time (Big-Oh notation)? Frequency count examine a piece code and predict the number of instructions to be executed (e.g...

T-SQL Script unconsitant in running time. Why?

I've got this script that runs on a SQL Server Express 2008 machine. /* BUD501T */ declare @ErrMsg nvarchar(4000) declare @ErrLine nvarchar(100) declare @currentFY nvarchar(1000) declare @programName nvarchar(1000) set @ErrMsg = '' set @ErrLine = '' set @programName = 'BUDPROD - GL_Exp.sql' select @currentFY = value from Budget...

Mergesort to sort three input arrays

A Merge algorithm merges two sorted input arrays into a sorted output array, by repeatedly comparing the smallest elements of the two input arrays, and moving the smaller one of the two to the output. Now we need to merge three sorted input arrays (A1, A2, and A3) of the same length into a (sorted) output array, and there are two method...

Inserting a new value in binary search tree

Using an algorithm Tree-Insert(T, v) that inserts a new value v into a binary search tree T, the following algorithm grows a binary search tree by repeatedly inserting each value in a given section of an array into the tree: Tree-Grow(A, first, last, T) 1 for i ← first to last 2 do Tree-Insert(T, A[i]) If the tree is i...