efficiency

What is more efficient in python new array creation or in place array manipulation?

Say I have an array with a couple hundred elements. I need to iterate of the array and replace one or more items in the array with some other item. Which strategy is more efficient in python in terms of speed (I'm not worried about memory)? For example: I have an array my_array = [1,2,3,4,5,6] I want to replace the first 3 elements ...

Efficient Cartesian Product algorithm

Can somebody please demonstrate for me a more efficient Cartesian product algorithm than the one I am using currently (assuming there is one). I've looked around SO and googled a bit but can't see anything obvious so I could be missing something. foreach (int i in is) { foreach (int j in js) { //Pair i and j } } This is a...

Java: Calculate SHA-256 hash of large file efficiently

I need to calculate a SHA-256 hash of large file (or portion of it). My implementation works fine, but its much slower than the C++'s CryptoPP calculation (25 Min. vs. 10 Min for ~30GB file). What I need is a similar execution time in C++ and Java, so the hashes are ready at almoust the same time. I also tryed the Bouncy Castle implement...

Fast algorithms for computing the factorial

I found this page describing a number of algorithms for computing the factorial. Unfortunately, the explanations are terse and I don't feel like sifting through line after line of source code to understand the basic principles behind the algorithms. Can anybody point me to more detailed descriptions of these (or other fast) algorithms f...

What is the best way to search multiple sources simultaneously?

I'm writing a phonebook search, that will query multiple remote sources but I'm wondering how it's best to approach this task. The easiest way to do this is to take the query, start a thread per remote source query (limiting max results to say 10), waiting for the results from all threads and aggregating the list into a total of 10 entr...

Loop: Need help with loop and efficiency

Currently, I need help with my loop. In each div, I want it to show two sets of FirstName and LastName instead of just one set, but I don't know how can I do that because of the loop. Also, the point of setting different font sizes is to create a visual look which is a funnel like shape. My question is, how can I add another set of name ...

A more efficient approach to Verbal arithmetic / Alphametics?

Perhaps most of you know the Send + More = Money. Well, I'm currently learning java and one of the exercises is I have to solve HES + THE = BEST. Now, so far I can/should use if-for-while-do loops, nothing else. Although I'm sure there are different methods to solve it, that's not the point of the exercise I'm going through. I have to b...

C# File I/O Efficiency

Hi, I have done a homework assignment, here is the problem statement: Your program should work as follows: Ask the user to give you a file name. Get the file name and save it. Open the file. From the file read a temperature and a wind speed. Both values should be stored in variables declared as double. The file is a text file. Each l...

efficiency of SQL 'LIKE' statement with large number of clauses

I need to extract information from a text field which can contain one of many values. The SQL looks like: SELECT fieldname FROM table WHERE bigtextfield LIKE '%val1%' OR bigtextfield LIKE '%val2%' OR bigtextfield LIKE '%val3%' . . . OR bigtextfield LIKE '%valn%' My question is: how efficient is this when the number o...

Tips for speeding up this code

Hiya, Can anyone suggest tips or alterations to make this code cleaner and faster? This was the only way I could think of doing it on a Friday evening, but I'm sure there must be a more efficient way of doing it... I know regexs aren't efficient but I can't honestly see how else I can do this, especially if the Postcode data can be an...

MySQL - large query vs Short query with multiple if's

This is a really broad question, but I have come across it a couple of times in the last few weeks and I was wondering what the general consensus is regarding good practice and efficiency. 1) SELECT COUNT(*) FROM table WHERE id='$id', name='$name', owner='$owner_id' and then based on if there is one result then the record matches. 2)...

Need advice on implementation for "heavy" operation involving iPhone (a lot of) AddressBook contacts.

Hello everyone, I am developing an SMS service application. At some point the user has to select the contacts he wants to send the SMS so he has 2 options. "Select all contacts" or "Select contacts". I have some issues regarding on how to implement the "Select all contacts" method since I want to achieve the following functionality: ...

Google Page Speed - what do these messages mean?

I ran the Google Page Speed Firefox extension on a few pages, and under "efficient CSS selectors" it listed various things that are inefficient in my CSS. But some of the messages seem a bit cryptic - what do these (in bold) mean: div#menu h3.soon small Tag key with 2 descendant selectors and ID overly qualified with tag and Class...

What language and (possible) web application framework should I use to develop a high traffic web application?

I'm currently in the pre-planning stages of a solo web application development project for university, which has about a year as time constraint. The application will have certain wiki-like features and may end up getting a high volume of traffic in the future, which is why whichever language and framework I choose must have as priority ...

Is there any significant difference between nesting a while loop in a while loop and nesting an if-else loop in a while loop? (C++)

EDIT: I forgot to add the loop part of the second code. Looking at the two code styles while(some_loop_cont_val) { while(pre_x is not done) { //do action pre_x } //do action x } and while(some_loop_cont_val) { if(pre_x is not done) { //do action pre_x } else { //do action x...

Is it more efficient to call the .net Garbage collector?

Due to the overhead of calling the garbage collector in the CLR, is it more efficient to leave it, or force to garbage collection when objects go out of scope? ...

iPhone animation efficiency solutions, layering questions

I'm working on writing a rather basic app. It uses minimal touch input, and mostly just plays fancy animations. There isn't much animation, but the way it's currently done seems super inefficient and uses far too much memory. The view is split into two parts, the bottom 1/5th is just one image that doesn't ever change. The rest of it i...

How much does the order of case labels affect the efficiency of switch statements?

Consider: if (condition1) { // Code block 1 } else { // Code block 2 } If I know that condition1 will be true the majority of the time, then I should code the logic as written, instead of: if (!condition1) { // Code block 2 } else { // Code block 1 } since I will avoid the penalty of the jump to the second code block ...

Collision Resolution : Quadratic Probing vs. Separate Chaining

Ok, so I've been doing some experiments with hash tables and different collision resolution problems. I'm trying to figure out which is more efficient for doing finds, a hash table that uses separate chaining or quadratic probing for collision resolution. My results suggest that separate chaining is faster than quadratic probing even for...

Erlang : Which is more efficient in this scenario - using try catch or case statements?

Say I have some function fn1() in Erlang which returns {ok, Result} if the function was executed successfully and {error, "ErrorReason"} if there was an error. Now in another function fn2() I call fn1() and I need to check the result of fn1 and proceed only if it is {ok, Result}. I figured, I can do this using either case or try catch...