efficiency

Best style for iterating through two lists in unison

Here is what I just wrote: public void mutate(){ ListIterator<Double> git = genome.listIterator(); Iterator<Double> mit = mutationStrategies.iterator(); while (git.hasNext() && mit.hasNext()){ git.set(alleleUpdate(git.next(), mit.next())); } } Is this the most efficient and clearest way of doing that? All tha...

Any tool to determine most efficient way of passing data, by reference or by value?

For objects or primitive data with a size equal to or less than size of a pointer the most efficient passing method to a function would definitely be by value but the thing is I want to know would be there any tool capable of determining best method of passing objects of classes or primitive data with a sizes bigger than size of a pointe...

ColdFusion: More efficient structKeyExists() instead of isDefined()

Which of these is more efficient in ColdFusion? isDefined('url.myvar') or structKeyExists(url, 'myvar') ...

MySQL statement convert to pretty Rails AR Statement?

Hi Guys, I have a MySQL statement that took me all night to come up with. I'm wondering if this thing can be converted from a direct call to something pretty like Object.find(:conditions) ActiveRecord::Base.connection.execute(" SELECT *, (SELECT COUNT(*) FROM scores AS temp2 WHERE temp2.score > scores.scor...

Making Regular Expression more efficient

I'm attempting to determine the end of an English sentence (only approximately), by looking for "!", "?" or ".", but in the case of "." only when not preceeded by common abbreviations such as Mr. or Dr. Is there any way to make the following Regular Expression even marginally more efficient? Perhaps by sorting the negative lookbehinds ...

Android: soft keyboard efficient key press effect?

on softkeyboard, which one is better to give user a visual feedback during keypress: 1.redraw portion of button that was pressed to background canvas of main View to give pressed effect 2.each button has its own "pressed" View, and that View is set to visible (flashing) during keypress event (so no redraw needed but need more memory) I...

loops efficiency

I came across through a presentation(dalvik-vm-internals) on Dalvik VM, in that it is mentioned as for the below loops, we have use (2) and (3) and to avoid (7). (1) for (int i = initializer; i >= 0; i--) (2) int limit = calculate limit; for (int i = 0; i < limit; i++) (3) Type[] array = get array; for (Type obj : array) (4) for (int...

When accessing individual characters in a string in Perl, is substr or splitting to an array faster?

I'm writing a Perl script in which I need to loop over each character of a string. There's a lot of strings, and each is 100 characters long (they're short DNA sequences, in case you're wondering). So, is it faster to use substr to extract each character one at a time, or is it faster to split the string into an array and then iterate o...

In C# is it a good practice to use recursive functions in algorithms?

In many functional languages using a recursion is considered to be a good practice. I think it is good because of the way compiler optimizes functional language's code. But is it a good practice to use recursion in C#, when creating an algorithm? Is it right to say in regards to C#, that recursive algorithms will result in your stack g...

What is an efficient algorithm for extracting bags from lists of pairs?

I have a list of pairs of objects. Objects can appear in the pair in either order. What is the most efficient algorithm (and implementation?) to find all bags (ie sets with duplicates permitted) of pairs between the same objects. For my purpose the object references can be assumed to be pointers, or names or some similar convenient, shor...

Is the Perl Goatse 'Secret Operator' efficient?

The "goatse operator" or the =()= idiom in Perl causes an expression to be evaluated in list context. An example is: my $str = "5 and 4 and a 3 and 2 1 BLAST OFF!!!"; my $count =()= $str =~ /\d/g; # 5 matches... print "There are $count numbers in your countdown...\n\n"; As I interprete the use, this is what happens: $str =~ /\d/g ...

FileStream.ReadByte - Inefficient - What is the meaning of this?

The default implementation on Stream creates a new single-byte array and then calls Read. While this is formally correct, it is inefficient. Any stream with an internal buffer should override this method and provide a much more efficient version that reads the buffer directly, avoiding the extra array allocation on every call. ...

python style: inline function that needs no inlining?

I'mm writing gtk code. I often have short callbacks that don't need to be closures, as they are passed all the parameters they need. For example, I have this in a loop when creating some gtk.TreeViewColumns: def widthChanged(MAINCOL, SPEC, SUBCOL, expandable): if expandable: return w = MAINCOL.get_width() SUBCOL.set_fixed_wi...

How do you find a missing number in a table field starting from a parameter and incrementing sequentially?

Let's say I have an sql server table: NumberTaken CompanyName 2                      Fred 3                      Fred 4                      Fred 6                      Fred 7                      Fred 8                      Fred 11                    Fred I need an efficient way to pass in a parameter [StartingNumber] an...

How would I make a thread join on another thread but only wait for n seconds of CPU time?

otherThread.join( time ) appears to wait time in real milliseconds. I want to wait time in actual CPU time so that I can get consistent behavior within my application. I've done a quick look at ThreadMXBean but that doesn't quite seem to have what I wanted ( it tells me the threads actual CPU time, but offers no convenient way to wait ...

C# anonymus delegates efficiency/safety

Hello I have progress form which delegate: // in ProgressForm thread public delegate void executeMethod(object parameters); private executeMethod method; public object parameters; // ... private void ProgressForm_Shown(object sender, EventArgs e) { method.Invoke(parameters); } Which way ...

How do you find a missing number in a table field starting from a parameter and incrementing sequentially?

Let's say I have an sql server table: NumberTaken CompanyName 2                      Fred 3                      Fred 4                      Fred 6                      Fred 7                      Fred 8                      Fred 11                    Fred I need an efficient way to pass in a parameter [StartingNumber] an...

How do I trim a log file with vb.net?

I'm writing a simple application in vb.net and need to output some information to a log file for diagnostic purposes. In order to ensure that the log file doesn't get too big, I need to trim it to a certain number of lines (say 5000). For performance reasons, the trimming doesn't have to occur each time a log entry is written out nor is...

Most efficient way to make the first character of a String lower case?

Given an input String, what is the most efficient way to make just the first character lower case? I can think of a number of ways to do this. For example, using charAt and subString: String string= "SomeInputString"; string = Character.toLowerCase( string.charAt(0)) + (string.length() > 1 ? string.substring(1) : ""); Or using a ch...

An Efficient way of randomizing an array - Shuffle code

Hi, I was asked this question in an interview and I gave various solutions but the interviewer was not convinced. I am interested to find a solution. Please throw in your views : Q: Write an efficient data structure to implement the shuffle in an ipod. It must play all the songs, each time in different random order, the same song shou...