efficiency

No duplicate rows, but redundant data

I have a mySQL table which represents a company's products. The table shows whether or not two products are compatible with each other. The table looks somewhat like Product1 Product2 Compatible? A A Yes A B ? A C No A D ? B A ? B ...

Is there a shortcut to normalizing a table where the columns=rows?

Suppose you had the mySQL table describing if you can mix two substances Product A B C --------------------- A y n y B n y y C y y y The first step would be to transform it like P1 P2 ? ----------- A A y A B n A C y B A y B B y B C n C A y...

Data structure for when key and value are equally "important"

So, this is probably a stupid question, but I have a mapping of unique IDs to unique values. Sometimes I want the value for a certain ID, sometimes I want to know the ID of a certain value. I search more than I modify the collection. I'm wondering if there's a special datastructure that makes sense here, or if I should just maintain two ...

Javasript/MooTools - Better to save element in object property vs. accessing each time with $('elem')?

In terms of speed/memory efficiency, does it make sense to save an element (retrieved via $) to a variable in an object or use $ to access it each time? Does accessing object properties (especially if nested a few levels - object within object) perform faster than using $? ...

Why is Collections.addAll supposed to be faster than c.addAll

The Java API docs say the following about Collections.addAll The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations. So if I understand correctly, a) is slower than b): a) Collection<Integer> col = new Arra...

how to "return an object" in C++

Hello, I know the title sounds familiar as there are many similar questions, but I'm asking for a different aspect of the problem (I know the difference between having things on the stack and putting them on the heap). In Java I can always return references to "local" objects public Thing calculateThing() { Thing thing = new Thing(...

int vs float arithmetic efficiency in Java

Hi all. I'm writing an application that uses Dijkstra algorithm to find minimal paths in the graph. The weights of the nodes and edges in the graph are float numbers, so the algorithm doing many arithmetics on float numbers. Could I gain a running time improve if I convert all weight to ints? Is int arithmetic operations are faster in J...

SQL efficiency - [=] vs [in] vs [like] vs [matches]

Just out of curiosity, I was wondering if there are any speed/efficiency differences in using [=] versus [in] versus [like] versus [matches] (for only 1 value) syntax for sql. select field from table where field = value; versus select field from table where field in (value); versus select field from table where field like value; ...

How expensive is find('count') in CakePHP?

I have a CakePHP application where I am trying to get a count of how many of each type of post a user has. I am also using the paginate helper to display all the user's posts on their profile. I could: 1) Make a find('all', $conditions) request for all the user's posts then parse that for the counts I need (by going post by post and chec...

Efficient way to find explanations of a method-test-matrix (mathematical problem)

Setup: I have a boolean matrix e.g. 1 0 1 1 0 1 where rows are named m1, m2, m3 (as methods) and columns t1 and t2 (as tests). Definition: An explanation is a set of rows (methods) which in union have at least one "1" in any column (every test hast to be matched by at least one method). in our example, the set of explanations ...

Please help transform Tsql "implicit joins" into explicit ones.

Sorry, I am pretty much an SQL noob. This has to work in MSFT SQL, Oracle as well as Sybase. In the following snippet I need to change an inner join between IJ and KL on IJ.PO_id = KL.PO_id into a left join also on IJ.PO_id = KL.PO_id. So, I believe I have to re-factor this. Well, implicit joins are not the most readable, at least in my ...

Linq query preferences

Hi, Learning a bit about Linq. I have the following code: (Please excuse the pathetic size of the data set) class Program { static void Main(string[] args) { var employees = new List<Employee> { new Employee { ...

MySQL SELECT efficiency

I am using PHP to interact with a MySQL database, and I was wondering if querying MySQL with a "SELECT * FROM..." is more or less efficient than a "SELECT id FROM...". ...

Java: case-statment or if-statement efficiency perspective.

Possible Duplicates: is else if faster than switch() case ? What is the relative performance difference of if/else versus switch statement in Java? I know that case statements can be implemented with jump tables. Does this make them more efficient than if statements? Is this just mico-optimization that should be avoided?...

Ruby on Rails coding efficiency - map CSV data to model

I have a question relating to minimizing some code I'm working with. I am using the map-fields plugin/gem to allow my user to select what fields in a CSV file will map to attributes in a model. map-fields with upload The map-fields plugin uses the name of a select object in the plugin to determine where the CSV columns match up too....

SQL Efficiency - Which is quicker?

Hi I'm doing a bulk insert but before inserting into the actual table I need to do some checks. So currently I'm inserting into a temp table but I've just seen that it's possible to declare tables. So my question is - Which is quicker? To CREATE or DECLARE. The table will have multiple SELECTS done on it and will contains around 200,000...

How do I maximize efficiency with numpy arrays?

Hi all, I am just getting to know numpy, and I am impressed by its claims of C-like efficiency with memory access in its ndarrays. I wanted to see the differences between these and pythonic lists for myself, so I ran a quick timing test, performing a few of the same simple tasks with numpy without it. Numpy outclassed regular lists by a...

PHP Coding Efficiency: How to fill an array without using [variableName++] (probably easy)

Something about using $array_increment++ to fill an array seem inefficient, even though it works. Is there a more efficient way to fill $color_names in the code below than using a variable to walk through the array? Since I'm using a foreach and 'if' to fill the array, it's harder to figure out a different way than using ++. $array_inc...

Efficient 2D drawing in Android

Hi everyone, I have searched for quite a few hours and have not been able to find a concise definite andswer to my question. I have an application where I need to draw a sports field (including all pitch lines) to the screen. So far, I have extended the SurfaceView and pretty much copied the rest of the LunarLander demo as well. All the...

Handling large datasets in Java/Clojure: littleBig data

I've been working on a graphing/data processing application (you can see a screenshot here) using Clojure (though, oftentimes, it feels like I'm using more Java than Clojure), and have started testing my application with bigger datasets. I have no problem with around 100k points, but when I start getting higher than that, I run into heap...