code-optimization

What is the most clever code you've ever seen?

My favorite is Tom "Duff's Device". It took me literally months after I first found this before I felt like I fully understood it. That said, I have seen others (there is an amazingly short implementation of a regular expression engine by Brian Kernighan in the book Beautiful Code). dsend(to, from, count) char *to, *from; int count; ...

C# running faster than C++?

A friend and I have written an encryption module and we want to port it to multiple languages so that it's not platform specific encryption. Originally written in C#, I've ported it into C++ and Java. C# and Java will both encrypt at about 40 MB/s, but C++ will only encrypt at about 20 MB/s. Why is C++ running this much slower? Is it bec...

Shorten up Jquery condition

Hi there, I have a question about how I can shorten a Jquery if statement. In my form I have several fields that I check if they are filled. I know there are several plugins to do that for me, but I wan't to learn it by myself (with some help of others ;-)) I got this check //---- First define hasError var hasError = false; //---- Ge...

Slow down my javascript! How to allow my code to wait for transition to complete before executing?

Strange Question i guess but i have this bit of code in my page... $(".map-overlay-left").click(function () { $("#map-holder").hide('slow'); var gmarkers = []; var side_bar_html = ""; var map = new GMap2(document.getElementById('map-holder')); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl())...

Self numbers in c++

Hey, my friends and I are trying to beat each other's runtimes for generating "Self Numbers" between 1 and a million. I've written mine in c++ and I'm still trying to shave off precious time. Here's what I have so far, #include <iostream> using namespace std; bool v[1000000]; int main(void) { long non_self = 0; for(long i = 1; i...

C++ Compiler Optimization for Fastest Possible Code in RAD Studio 2009

I would like to select the compiler optimizations to generate the fastest possible application. Which of the following settings should I set to true? Dead store elimination Eliminate duplicate expressions within basic blocks and functions Enable loop induction variable and strength reduction Enable pentium instruction scheduling Expan...

How to simplify this logic/code?

I want to write an apps that accepts user command. The user command is used in this format: command -parameter For example, the app can have "Copy", "Paste", "Delete" command I am thinking the program should work like this : public static void main(String args[]){ if(args[0].equalsIgnoreCase("COPY")){ //handle the copy co...

Which method of assignment will work faster?

What will work faster? How strongly will it affect productivity? $test = new Test(); $a1 = array(); $a2 = array(); $a3 = array(); $a1[1] = $test; $a2['qwe'] = $test; $a3[] = $test; ...

Loop Code Optimization

How can I optimize the following code , I Need to run 3 sets of loops like this: for($i=1;$i<=$count-1;$i++){ for($j=$i+1;$j<=$count;$j++){ // do some query use $i and $j } } for($i=1;$i<=$count-2;$i++){ for($j=$i+1;$j<=$count-1;$j++){ for($k=$j+1;$k<=$count;$k++){ // do some query use $i and $j and $k ...

$ not defined - javascript error, tried to optimize files

HI guys, my application uses a lot of different javascript files. SO I tried to be quick about it and accomodate all the files in one single file. This I did by creating a single php with the following code: <?php header('Content-type: text/javascript'); $js = array( .... ); // all files to include $js = array_unique($js); foreach...

My page takes too long to load! How can I cut the page load time!

Hi guys I'm testing out my application. Using firebugs I've found out my application is abominably slow and needs to speed up. I have one huge clumped up javascript file thats over 700KB, that includes all my js libraries but the spooky part is the code itself takes anything between 20 to 40 seconds to run. Now the thing is that my code...

Is there a faster way to retrieve a message using zend framework libraries?

Hi guys I'm building a simple mail interface for my application but I've noticed that its really slow especially when the user has to list out a number of emails. I've traced the time taken for code to execute and found that just the $mail->getMessage function takes around 0.6 seconds to execute. My code is as below: $mail = new Zend_M...

Combining JavaScripts files

I'm using a blogger platform for blogging. I've many widgets on my blog which refer to JavaScript files on the different servers, which is affecting loading performance of my blog. Can I combine those files into one in order to reduce my requests to those servers? Or is there any other way to optimize my JavaScript code? ...

Is there a crowdsourcing site for code optimization?

I like clean and well written code, but I don't have the experience or the knowledge (yet) to write code at his best; so, I was wondering if there's a site (like SO) where people can submit snippets, clases, implementations, etc., to be reviewed and posibly improved by other experiencied people, so everybody could learn from their modifi...

Different Code in for loops

Hey everyone, I have created a rather complicated piece of (Java) code for a game I am working on. I'm fairly sure I will need to change it in the future to optimize or otherwise change the exact functioning. The code is able to efficiently loop through a subset of the game entities. The problem is that while looping over this subset...

Remove foreach - c# code-optimization

How to optimize this code? ParentDoglist, ChildDoglistis - Ilist. dogListBox - List Box foreach (Dog ParentDog in ParentDoglist) { foreach (Dog ChildDog in ChildDoglist) { if(ParentDog.StatusID==ChildDog.StatusID) dogListBox.Items.Add(new ListItem(ParentDog.Name, ParentDog.Key)); } } EDIT: ParentDogTypeList, DogTypeList were ...

Finding the highest-n values in a Map

I have a large map of String->Integer and I want to find the highest 5 values in the map. My current approach involves translating the map into an array list of pair(key, value) object and then sorting using Collections.sort() before taking the first 5. It is possible for a key to have its value updated during the course of operation. I...

How can I perform code optimisation on the following program?

func() { fun1(); fun2(); fun3(); fun4(); fun5(); fun6(); .. .. .. .. fun99(); fun100(); } by using function pointers in C program? I need to call this program repeatedly in my program. ...

About code optimization in Flash AS3

Hi, i'm curious about something. Let say we have 30 object in the code, and every object should be animated trough enter frame event. Which will be faster(in terms of memory execution) : to have just one event listener in the main object (for example) and to call object methods, or, to have separate event listener for every object? Thank...

More efficient ways of doing this

for i in vr_world.getNodeNames(): if i != "_error_": World[i] = vr_world.getChild(i) vr_world.getNodeNames() returns me a gigantic list, vr_world.getChild(i) returns a specific type of object. This is taking a long time to run, is there anyway to make it more efficient? I have seen one-liners for loops before that are sup...