efficiency

Checking whether two numbers are permutation of each other?

Given two numbers a, b such that 1 <= a , b <= 10000000000 (10^10). My problem is to check whether the digits in them are permutation of each other or not. What is the fastest way of doing it? I was thinks of using hashing but unable to find any suitable hash function. Any suggestions? For e.g - 123 is a valid permutation of 312 A...

Most efficient way of implementing this?

Hi Guys, I've got a 1km square, I'm dividing it up into 100meters both on the positive and negative sides of it.. __________y__________ | | | | | | | | | |---------|---------| x | | | | | | ...

Ways to improve efficiency of C# code

Hi all, Like most of us, I am a big fan of improving efficiency of code. So much so that I would rather choose fast-executing dirty code over something which might be more elegant or clean, but slower. Fortunately for all of us, in most cases, the faster and more efficient solutions are also the cleaner and the most elegant ones. I u...

What's the best way to make a bitwise function work for any type of integer input c++?

So I need to read flags in bits and set flags in bits. These bits are in various sizes of integer: int16, int32, int64, etc. I would like to have a function that does something like this: static integertype function(integertype data, char startbit, char endbit); I don't want to code what will be the same code to isolate bits from for...

Which of these methods is most effective when I traverse a List?

List<T> list = new ArrayList<T>(); 1 method: for(int i = list.length - 1; i >= 0; i--) { System.out.println(list.get(i)); } 2 method: for(T t : list) { System.out.println(t); } 3 method: Iterator<T> it = list.iterator(); while(it.hasNext()) { System.out.println(it.next()); } ...

To double a value, is <<1 more efficient than *2

Possible Duplicate: Is shifting bits faster than multiplying and dividing in Java? .NET? To double a value, is <<1 more performant than *2 in modern languages? I'm particularly interested in Java and C#. Does having optimization turned on at compile-time change things? ...

SIGALRM Timeout -- How does it affect existing operations?

I am currently using select() to act as a timer. I have network receive operations which occur within a loop, and every few seconds a processing operation needs to occur. As a result, the select() statement's timeout constantly changes -- decreasing to zero over time and then restarting at 3. rv = select(selectmonitor+1, &readnet, NULL...

how to make a script be active for only on every hour on the half hour?

Hello all. I have a script and I want to code it so that it becomes active every hour on the half hour. This is the code I have so far. from ConfigParser import * import emailModule from datetime import datetime import time configuration = ConfigParser() configuration.read('Email.conf') email = emailModule.emailModule(configuration) ...

Improvements to memory leak hunting.

Hello, I just spent a whole week tracking down and whacking memory leaks over the head, and I arrived on the other end of that week a little dazed. There has to be a better way to do this, is all I can think, and so I figured it was time to ask about this rather heavy subject. This post turned out to be rather huge. Apologies for that,...

STL: Set of natural numbers from A to B

I want to add natural numbers from A to B in a set. Currently I am inserting each and every number from A to B, one by one in the set like this, set<int> s; for(int j=A; j<=B; j++) s.insert(j); But it takes O(n) time (here n = (B - A)+1). Is there any pre-defined way in STL to do it in O(1) time? Thanks ...

The Rails Way for Reducing HTML Duplication

In my .html.erb file, I have a lot of lines of information to display. I am accomplishing this with a simple: (using blueprint css) <% for event in @user.events %> <div class="span-5 border">Descriptor:</div> <div class="span-5 last"><%=h event.foo%></div><br/> <% end %> How can I make it so that I can call some function that would re...

Sparse vs Normal Array Matlab

In Matlab, at what point is having a sparse array better than a normal array if I still have a lot of calculations to do on it, and about 25% of the array are non-zeros? ...

Data design - multiple short trips vs one big trip

Boiled down: Is it better to have the calculated field returned with the rest of the results or is it better to calculate it later when you need it? Example: I have a GridView that displays search results that has many fields like: Application ID Name Account Type Account Number etc. The account number field is not always consisten...

Regular expression performance in Java -- better few complex or many simple?

I am doing some fairly extensive string manipulations using regular expressions in Java. Currently, I have many blocks of code that look something like: Matcher m = Pattern.compile("some pattern").matcher(text); StringBuilder b = new StringBuilder(); int prevMatchIx = 0; while (m.find()) { b.append(text.substring(prevMatchIx, m.start()...

n*n table vs (n^2)*3 table in mysql

A while back I posted a different question regarding column order. While this question does not relate to column order, I was suggested to make my table differently from how I was making it. Lets say I am selling 100 products. Some of these products are compatible with each other, some are not. Some have not been tested yet (I did not m...

Most efficient way to calculate the exponential of each element of a matrix

I'm migrating from Matlab to C + GSL and I would like to know what's the most efficient way to calculate the matrix B for which: B[i][j] = exp(A[i][j]) where i in [0, Ny] and j in [0, Nx]. Notice that this is different from matrix exponential: B = exp(A) which can be accomplished with some unstable/unsupported code in GSL (linalg....

Python list, lookup object name, efficiency advice

Suppose I have the following object: class Foo(object): def __init__(self, name=None): self.name = name def __repr__(self): return self.name And a list containing multiple instances, such as: list = [Foo(name='alice'), Foo(name='bob'), Foo(name='charlie')] If I want to find an object with a given name, I could use the ...

give the job to MySQL or to PHP?

I have some several codes in PHP to do jobs that MySQL could do. such as sorting, merging each data from different MySQL tables, etc... Lately, I found out that I can do all these stuffs with one MySQL query. I am wondering is it better to give the MySQL capable jobs to MySQL or to PHP. efficiencies, speed, etc.. Thank You, ...

MySQL - Query to find a continuous range of unused values

Hi, I have a table containing integer values from 0 to some large number N, but has some number gaps. I'm trying to write an efficient query that'll find the first set of continuous values of some length that are within 0 and N but are not contained in the said table. This has applications to find unused ids, etc. For example, given th...

How to create an efficient loop for performing actions every X minutes in windows services?

I'm writing a windows service that should perform an action every, lets say, 60 seconds. How is the best way to implement that main loop? Implementations I've seen so far: 1) Using a Timer object that executes a delegate every xx seconds 2) Using ManualResetEvents (the implementation I've seen only executes once, but as far as I unders...