efficiency

Speed up a query, simple inner join with one large table and one small table.

I have a table T1 with 60 rows and 5 columns: ID1, ID2, info1, info2, info3. I have a table T2 with 1.2 million rows and another 5 columns: ID3, ID2, info4, info5, info6. I want to get (ID1, ID2, info4, info5, info6) from all the rows where the ID2s match up. Currently my query looks like this: SELECT T1.ID1, T2.ID2, T2.info4,...

read files from directory and filter files from Java

The following codes goes through all directories and sub-directories and outputs just .java files; import java.io.File; public class DirectoryReader { private static String extension = "none"; private static String fileName; public static void main(String[] args ){ String dir = "C:/tmp"; File aFile = new F...

how to reuse subquery result in mysql

I'm doing a statistic job like this: SUM |COND1 |COND2 |... -------------------------- 100 |80 | 70 |... The SUM result is calculated from multiple tables, and the CONDs are subset of that. I wrote a sql like this: select tmp1.id,sum,cond1,cond2 from ( select id, count(*) as sum from table1 group by table1.id) tmp...

Java anonymous class efficiency implications

Is there any difference in efficiency (e.g. execution time, code size, etc.) between these two ways of doing things? Below are contrived examples that create objects and do nothing, but my actual scenarios may be creating new Threads, Listeners, etc. Assume the following pieces of code happen in a loop so that it might make a difference...

Better ways to create various kind of View Controllers on iPhone?

The thing is this: when we program for an iPhone app, we can add some more classes for those view controllers and such. But honestly, debugging and compiling these kind of programs get old real fast. Sure, we have the iPhone simulator, but sometimes, you just have to change some tiny things and you have to compile again. This is tedious....

Calculating all distances between one point and a group of points efficiently in R

Hi, First of all, I am new to R (I started yesterday). I have two groups of points, data and centers, the first one of size n and the second of size K (for instance, n = 3823 and K = 10), and for each i in the first set, I need to find j in the second with the minimum distance. My idea is simple: for each i, let dist[j] be the distanc...

what's more efficient? checking == or just mutating the variable?

Imagine I had a variable called X. Let's say every 5 seconds I wanted to make X = true. (it could be either true or false in between these 5 seconds, but gets reset to true when the 5 seconds are up). Would it be more efficient to check if the value is already true, then if not, reassign it to true? Or just have X = true? in other word...

How to efficiently get highest & lowest values from a List<double?>, and then modify them?

I have to get the sum of a list of doubles. If the sum is > 100, I have to decrement from the highest number until it's = 100. If the sum is < 100, I have to increment the lowest number until it's = 100. I can do this by looping though the list, assigning the values to placeholder variables and testing which is higher or lower but I'm wo...

Is checking no.of rows before fetching them more efficient than directly fetching all data in hibernate?

I have below scenario Got n as minimum number of database required for the transaction. Issue select count(*) query to find out number of rows satisfying the criteria. if the result of step 2 is greater than or equal to n, then proceed further or throw exception. Fetch actual objects by limit to n in hibernate query. do the logic and s...

What's the best way to write to more files than the kernel allows open at a time?

I have a very large binary file and I need to create separate files based on the id within the input file. There are 146 output files and I am using cstdlib and fopen and fwrite. FOPEN_MAX is 20, so I can't keep all 146 output files open at the same time. I also want to minimize the number of times I open and close an output file. How ...

Local variable vs parameter

function doIt(param) { var localVar = param; //do lots of stuff with localVar } function doIt(param) { //do lots of stuff with param } Is there any difference in terms of efficiency between the code above? ...

SQL sub queries - is there a better way

This is an SQL efficiency question. A while back I had to write a collection of queries to pull data from an ERP system. Most of these were simple enough but one of them resulted in a rather ineficient query and its been bugging me ever since as there's got to be a better way. The problem is not complex. You have rows of sales data. ...

SQL: Performance comparison for exclusion (Join vs Not in)

Hello, I am curious on the most efficient way to query exclusion on sql. E.g. There are 2 tables (tableA and tableB) which can be joined on 1 column (col1). I want to display the data of tableA for all the rows which col1 does not exist in tableB. (So, in other words, tableB contains a subset of col1 of tableA. And I want to display t...

Nested for loop in xquery

Hi, I want to compare the elements on a list using XQuery. For this I'm thiking about using two for loops nested. Something like this: for $i in $node[*[name(.)=$dN][data(.)!=""] and *[name(.)=$hN][data(.)!=""]] return { for $j in $node[*[name(.)=$dN][data(.)!=""] and *[name(.)=$hN][data(.)!=""]] and $j != $i ...

[c] Array index efficiency (specifically, temporary vars)

I've read a fair amount of stuff about efficiency of array indices vs. pointers, and how it doesn't really matter unless you're doing something a lot. However, I am doing this a lot. The code in question has an array of structs. (Two different ones, for two different types actually, but whatever). Since my background is mostly in hig...

Best Practice for IF/ELSE Statement Order (when one case is never allowed).

In a simple if-else case (where the denominator of a fraction will need to be checked for a value of zero for each entry), does a correct arrangement of the statements even exist? For example: if (!(denominator == 0)) { quotient = numerator / denominator; System.out.println(numerator + " / " + denominator + " = ...

Efficient filesystem searching

I am writing a program which searches through all the sub-directories of a given directory. The problem is, is that I know the name of the file that I am looking for (data.txt) but I still need to know all of the (possibly multiple) locations where the file is. I am using this code to search: struct dirent *dp; struct stat s; DIR *dir; ...

Which jQuery code is more efficient?

Hello All - Out of curiousty which of the following code is more efficient (if neither, what would be the best way?) Backstory - Building a small image carousel and the code in question has to do with the controls (prev, pause/play, next) <ul class="controls"> <li> <a href="#" class="prev"> Previous Image </a> </li> <li> <a h...

What is an appropriate page processing time for a web application?

I'm working on a web application, and it's getting to the point where I've got most of the necessary features and I'm starting to worry about execution speed. So I did some hunting around for information and I found a lot about reducing page load times by minifying CSS/JS, setting cache control headers, using separate domains for static ...

Touch-typing capital letter identifiers

Hi all, About half year ago I decided to improve my programming efficiency, so I learned touch-typing and moved to Vim. All is fine and I feel myself much better than before. However there is a question that annoys me all that time: how should I touch-type IDENTIFIERS_WRITTEN_IN_CAPS? If I will use shifts by all rules, I would have to...