efficiency

What is more efficient i++ or ++i?

Exact Duplicate: Is there a performance difference between i++ and ++i in C++? Exact Duplicate: Why should I use ++i? Exact Duplicate: Difference between i++ and ++i in a loop? What is more efficient i++ or ++i? I have only used this in Java and C/C++, but I am really asking for all languages that this is implemented in. In colleg...

Check if variable null before assign to null?

Is variable assignment expensive compared to a null check? For example, is it worth checking that foo is not null before assigning it null? if (foo != null) { foo = null; } Or is this worrying about nothing? ...

Sort algorithm to use for this specific scenario

I have two lists - let's call them details and totals. The items in details have multiple elements for each key that the list is sorted on, as such: KEY1 KEY1 KEY2 KEY2 KEY3 KEY3 KEY3 etc The items in totals will only have each key once, as such: KEY1 KEY2 KEY3 etc Both lists are sorted by key already. The lists need to be combined...

Will the C/C++ compiler optimize this if statement?

I have code like this, and I find it a bit hard to read: // code1 if( (expensiveOperation1() && otherOperation() && foo()) || (expensiveOperation2() && bar() && baz()) { // do something } I just changed it to the following, to make it more readable: // code2 const bool expr1 = expensiveOperation1() && otherOperation() && foo(...

is there a difference between absolute and relative paths when pointing to certain files on your html?

our office just got this new guy with lots of experience and kept insisting that we stop using absolute paths like: http://somesite.com/subdir1/images/filename.ext when pointing to a path of our image when it resides next to the file that calls it say we could have just used: ./subdir1/images/filename.ext but the reason why we used abso...

Indy Write Buffering / Efficient TCP communication

I know, I'm asking a lot of questions...but as a new delphi developer I keep falling over all these questions :) This one deals with TCP communication using indy 10. To make communication efficient, I code a client operation request as a single byte (in most scenarios followed by other data bytes of course, but in this case only one sin...

The most efficient way to parse Xml

The .Net framework now has (at least) four different methods of reading an Xml string. I've used each of XmlDocument, XmlReader, XPath and XElement, but which is the most efficient to use when coding or during execution? Is each designed for a different task, what are the pros and cons? Update: Using a XmlReader appears to be the quic...

Faster CompareText implementation for D2009

Hello, I'm extensively using hash map data structures in my program. I'm using a hash map implementation by Barry Kelly posted on the Codegear forums. That implementation internally uses RTL's CompareText function. Profiling made me realize that A LOT of time is spent in SysUtils CompareText function. I had a look at the Fastcode site...

What's the most efficient test of whether a PHP string ends with another string?

The standard PHP way to test whether a string $str ends with a substring $test is: $endsWith = substr( $str, -strlen( $test ) ) == $test Is this the fastest way? ...

Best method for storing a list of user IDs

I'm working on a PHP/MySQL rating system right now. For the user to be able to rate the user has to log in. Each user has a unique "UID". There will be multiple rating instances on the website (one for every game, in my case) and I need an efficient way of storing a list of UIDs in a MySQL row (one MySQL row in the ratings table for each...

Efficient MySQL table structure for rating system

This post is a follow-up of this answered question: Best method for storing a list of user IDs. I took cletus and Mehrdad Afshari's epic advice of using a normalized database approach. Are the following tables properly set up for proper optimization? I'm kind of new to MySQL efficiency, so I want to make sure this is effective. Also,...

Is querying a single record from a MySQL view including thousands, equivalent to querying those thousands + 1?

I have always hoped and assumed that it is not - that set theory (or something) provides a shortcut to the result. I have created a non-updateable view that aggregates data from several tables, in a way that produces an exponential number of records. From this view, I query one record at a time. Because the underlying dataset is small, ...

Which is more efficient, PHP string functions or regex in PHP?

I'm writing PHP code to parse a string. It needs to be as fast as possible, so are regular expressions the way to go? I have a hunch that PHP string functions are more expensive, but it's just a guess. What's the truth? Here's specifically what I need to do with the string: Grab the first half (based on the third location of a substrin...

overhead to unused "using" declarations ?

I've just installed resharper and it's letting me know the namespaces i'm not actually using in each of my classes. which lead me to the question - is there actually any overhead in leaving these, unused, using declarations in? is it just a matter of tight code, or is there a performance hit in invoking these namespaces when i don't ne...

Is Disney's FastPass Valid and/or Useful Queue Theory

At Disney World, they use a system called Fastpass to create a second, shorter line for popular rides. The idea is that you can wait in the standard line, often with a wait longer than an hour, or you can get a FastPass which allows you to come back during a specified time block (usually a couple hours later) and only wait for 10 minute...

AJAX and Javascript cache efficiency question

I am building a simple blog which is viewed single-page (do not worry, it is progressively built) and thus I am sending AJAX requests which return HTML to be inserted into the page. What is the most efficient way to store/cache information (HTML) to be added at a later time into the DOM? How much information (old entries which the user...

How to improve productivity when developing JEE based web applications.

I'd like to know how you address the seemingly low productivity of JEE-based web application development compared to other technology stacks (Seaside, Ruby on Rails, etc). The constraints are: The finished web application must be deployable on JEE compliant application containers If possible, previous investment in Java-based solution...

Most Efficient Method to Detect Column Change in MS SQL Server

Our system runs on SQL Server 2000, and we are in the process of preparing for an upgrade to SQL Server 2008. We have a lot of trigger code where we need to detect a change in a given column and then operate on that column if it has changed. Obviously SQL Server provides the UPDATE() and COLUMNS_UPDATED() functions, but these functions...

What are the benefits to closing a form and reloading all the data as opposed to hiding and showing the form in C#?

When working with Windows forms in C#, is it safer/more beneficial resource-wise to completely close the form each time and reload the data when you need the form again, as opposed to just hiding the form and keeping it all in memory? ...

Pros/Cons to increasing the scope of a repository instance?

The title to this question isn't written very well. Sorry 'bout that. I'm curious what the pros or cons would be to increasing the scope of an object instance within a method to the class level. As a specific example, I have a non-static service class that wraps access to a repository class which is used to manage CRUD activity as w...