optimization

stristr and speed

Hi, I've got two files,file a around 5mb, and file b around 66 mb. I need to find out if there's any occurnaces of the lines in file a, inside file b, and if so write them to file c. This is the way I'm currently handling it: ini_set("memory_limit","1000M"); set_time_limit(0); $small_list=file("a.csv"); $big_list=file_get_contents("b.c...

Would the CLR optimize and inline this GetHashCode()?

Let's say we have a value type like this, where the fields are readonly and initialized during construction: public struct SomeValue { private readonly Int32 field1; private readonly Int32 field2; ... } Also, let's say we have a helper class that lets us implement GetHashCode() for composite types in a reusable manner: p...

How to optimize norm calculation in Matlab ?

I had like to optimize the following Matlab code : x = linspace(-5,5,100); y = linspace(-5,5,100); z = linspace(-5,5,100); [xp,yp,zp] = meshgrid(x,y,z); norm = sqrt(xp.^2+yp.^2+zp.^2); I improved it a little using realsqrt : norm_0 = sqrt(xp.^2+yp.^2+zp.^2) 10.106 s 37.0% norm_1 = realsqrt(xp.^2+yp.^2+zp.^2) 1...

Optimizing C++ code for performance

Can you think of some way to optimize this piece of code? It's meant to execute in an ARMv7 processor (Iphone 3GS): 4.0% inline float BoxIntegral(IplImage *img, int row, int col, int rows, int cols) { 0.7% float *data = (float *) img->imageData; 1.4% int step = img->widthStep/sizeof(float); // The subtraction by o...

How to find out what optimizations the JVM applied to my code?

The JVM (especially the HotSpot VM) is famous for having a huge number of optimizations it can apply at runtime. Is there a way to look at a certain piece of code and see what the JVM has actually done to it? ...

Optimal database structure design for one to many

I am building an inventory tracking system for internal use at my company. I am working on the database structure and want to get some feedback on which design is better*. I need a recursive(i might be using this term wrong...) system where a part could be made up of zero or more parts. I though of two ways to do this but am not sure wh...

mysql query optimization

SELECT b.categoryid, SUM(viewcount) AS cnt, categoryname FROM bookvisit AS bv INNER JOIN book AS b ON b.isbn = bv.isbn LEFT JOIN category AS c ON b.categoryid = c.categoryid WHERE b.categoryid IS NOT NULL AND b.categoryid <> 0 GROUP BY b.categoryid ORDER BY cnt DESC, bv.isbn LIMIT 0, 4 I ha...

How can I optimize my screencasting utility?

I'm developing a screencasting utility in C++. It basically captures desktop frames and creates an AVI file. The algorithm is as follows: Create a thread: this->m_hThread=CreateThread(NULL,0,thScreenCapture,this,0,NULL); Capture desktop in thScreenCapture n times per second (like 5 fps). obj->Capture(); In Capture(), append the bitm...

Numpy: How to split/partition a dataset (array) into training and test datasets for, e.g., cross validation?

What is a good way to split a numpy array randomly into training and testing / validation dataset? Something similar to the cvpartition or crossvalind functions in Matlab. ...

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. ...

How should I start profiling/optimizing my java application/oracle database?

Yesterday I read something abouth application optimization and how a programmer should find the most used parts of the program and by profiling and modifying them getting the most benefit (when looking at the time/work invested vs. memory/speed gains). Now, I've run the Eclipse profiler, got VisualVM but I don't how to use this data prop...

Can we detect if a site is on CDN?

Is there a way to detect if a site is on a Content Delivery Network and if yes, can we tell which service are they using? ...

Fast multiplication of values in an array

Is there a fast way to multiply values of a float array in C++, to optimize this function (where count is a multiple of 4): void multiply(float* values, float factor, int count) { for(int i=0; i < count; i++) { *value *= factor; value++; } } A solution must work on Mac OS X and Windows, Intel and non-Intel....

JavaScript - run once without booleans

Is there a way I can run piece of javascript code ONCE without the use of boolean flag variables to know that it already ran? Specifically not something like: var alreadyRan = false; function runOnce() { if (alreadyRan) { return; } alreadyRan = true; /* do stuff here */ } I'm going to have a lot of these types of funct...

Improve performance with blitting.

I am a bit new to using blitting for graphics. But I have worked up a few demos myself, and I have been reading a lot of information on the methods used. One common theme I have been seeing though is that all of them brute force rendering; drawing the farthest back object first and stepping through all other objects. even drawing object...

Optimizing the data access layer

Hi, all. I have a web service (JAX-RS/Spring) that generates SQL queries which run against a temp table in Oracle. The data is then archived to another table (through 3 MERGE statements). The execution of each "job" (querying and merging) is done in the background through a JMS broker (ActiveMQ). The sequence of operations of each job i...

A weighted version of random.choice

I needed to write a weighted version of random.choice (each element in the list has a different probability for being selected). This is what I came up with: def weightedChoice(choices): """Like random.choice, but each element can have a different chance of being selected. choices can be any iterable containing iterables w...

One query per page - is it that bad?

I am creating RPG type game. I pull out player's information in every page loaded from two tables with JOIN (it is information about member: age, name, his all game's stats and etc) and sometimes this information is required for me, sometimes not at all. Two tables consists of ~60-70 rows. Here is an example: $query = mysql_query("SELEC...

How to optimize my current getMax method to retrieve the highest number in an array?

What would be the best way to optimize this code below to make it more efficient while applying the 'best practices'. This is just a simple school project and it works, I've tested it. But I just feel like there's a better and more efficient way to write this method. What do you think? I have an array that is pre-populated with a bunch...

lighttpd fastcgi optimization

I have a web service using lighttpd and fastCGI (using TCP) where lighttpd causes a processor bottleneck. How can I optimize the performance of lighttpd and fastCGI? Best Regards ...