efficiency

mySQL - One large query vs Ajax indivdual queries

Hi guys, I guess no one will have a definative answer to this but considered predictions would be appriciated. I am in the process of developing a mySQL database for a web application and my question is: Is it more efficient to make a single query that returns a single row using AJAX or To request 100 - 700 rows when the user will l...

What is the most efficient method for looping through a SortedList in VB 2008?

The code below shows me (I think) that the "for each" loop is about 10% faster than the "i to n" loop, but the "for each" loop creates 567k in new memory? Is this right? Which way is generally most efficient with regards to speed and memory usage? If you want to run this code in VB just add a button and 2 labels to a form. Public Class...

Is it more efficient to compare ints and ints or strings and strings

I've got a program written in c# where there are a lot of comparisons between ints and strings. So for performance reasons I would just like to know which is more efficient? If we have: int a = 5; string b = "5"; if(a == int.Parse(b)) { } OR if(a.ToString() == b) { } ...

How do you balance business process changes against the challenges of changing software?

In my admittedly young career I've found myself writing code to support quirky business rules and processes. Inevitably these changes were always in some massively difficult code base and caused many issues. My question has a couple of parts: While software is a tool for businesses to make their lives easier, at what point do we as d...

Purging SQL Tables from large DB?

The site I am working on as a student will be redesigned and released in the near future and I have been assigned the task of manually searching through every table in the DB the site uses to find tables we can consider for deletion. I'm doing the search through every HTML files source code in dreamweaver but I was hoping there is an aut...

Execute Code Segment only if Loop reaches its last cycle (End of Loop)

Where is the most efficient position for a code block, which shall only execute, if a loop has reached its end, without having previously been aborted (via break or return)? The question seems banal, the answer obvious, nevertheless I am insecure! Answer from efficiency/theory professionals very welcome! Provided: "Some Code X" is ...

Efficient way to display Inbox(1) count in a webapp w/o calling DB for each page request

In my web application we have built a message center / inbox functionality, in the navigation of each page we link to the "Message Center" and include next to it a count of the unread messages, for example "Message Center (2)". To populate the (2), with each request we run a *SELECT COUNT(*) FROM MessageTable WHERE unread = true blah bl...

mySQL - A new table of each page?

Every page on my application will display 1000 records and they are only needed on that page. Is it more efficient to have one huge table with an additional 'page id' column or to have a new table for each page? I imagine accessing data from a single small table would be easier than a huge one but it will make the database a bit of a m...

Is converting a NameValueCollection to a querystring using a c# lamdba efficient?

In researching how to convert a NameValueCollection to a querystring, I have come across different methods. I am curious if the shorter lambda syntax is as efficient as it could be. How to convert NameValueCollection to a (Query) String using a iterating function. public static String ConstructQueryString(NameValueCollection parameter...

charAt() or substring? Which is faster?

I want to go through each character in a String and pass each character of the String as a String to another function. String s = "abcdefg"; for(int i = 0; i < s.length(); i++){ newFunction(s.substring(i, i+1));} or String s = "abcdefg"; for(int i = 0; i < s.length(); i++){ newFunction(Character.toString(s.charAt(i)));} Th...

Efficiently finding the ranks of elements in an array?

How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example: float[] rank(T)(T[] input) { // Implementation } auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5] The only way I can think of doing it requires allocating 3 arrays: A duplicate of the input array because...

Quicker ways to search a C# List<String>

I currently have a list called regkey and a string called line_to_delete, which I obviously want to delete from the list. At the moment I'm searching through one element of the list at a time creating substrings as line_to_delete only represents part of the line that I want to delete but is uniquely identifiable within the list. Anyway ...

Python: How much space does each element of a list take?

I need a very large list, and am trying to figure out how big I can make it so that it still fits in 1-2GB of RAM. I am using the CPython implementation, on 64 bit (x86_64). Edit: thanks to bua's answer, I have filled in some of the more concrete answers. What is the space (memory) usage of (in bytes): the list itself sys.getsizeof(...

Bitwise XORing and shifting of integer arrays

Suppose a bit sequence of size M, and another bit sequence of size N, with M >> N. Both M and N can be saved inside integer arrays: If N has a length of 30 then an array with only one integer will be needed, but if N has a length of 300 then an array with 10 integers will be needed to store it. What I am trying to do is to shift N insi...

Efficient latest record query Postgresql

Alright I need to do a big query, but I only want the latest records. For a single entry I would probably do something like SELECT * FROM table WHERE id = ? ORDER BY date DESC LIMIT 1; But I need to pull the latest records for a large (thousands of entries) number of records, but only the latest entry. Here's what I have but It's no...

Loop and MySQL help!

Okay, basically... i am trying to store the dates and month name from my database in this format. I am aiming store the month and then count the entries in that month and then store the count. This is my loop, but I have trouble formatting the array properly. while ( $row = mysql_fetch_assoc($res) ) { if ($row['Date'] != $prev_date) {...

How does a programmer work across multiple computers?

I always find myself close to useless without my laptop. It has all the things I need, firefox, notpad++, photoshop, documents, etc... However, occasionally, I like to code on my desktop because it's faster and better, but sometimes it's just impossible unless I transfer the website files to my desktop or keep my FTP updated. I know ther...

When developing a website...

Very often, I just create a new folder and test things out in there. I use remote upload and then edit and refresh the page to see if it works. Now, one time when I was asked to work on a friend's website, he told me to change the IP for his domain in my HOSTS windows file. He had a clone of his website on another server, so I could edit...

Can my code be more efficient?

I have to put my database's data in this format (values will differ, obviously), I think it's called an associative array (I'm horrible with terminology). $values=array( "Jan" => 110, "Feb" => 130, "Mar" => 215, "Apr" => 81, "May" => 310, "Jun" => 110, "Jul" => 190, ...

Packet detection using regex

I'm new to regular expressions, and I need to write a set of regular expressions that match different data packet formats. My problem is, usually I only need to look for the start and ending parts of the packet to distinguish between them, the data in between is irrelevant. What's the most efficient way to ignore the data between the s...