optimization

Coin flipping game: Optimization problem

There is a rectangular grid of coins, with heads being represented by the value 1 and tails being represented by the value 0. You represent this using a 2D integer array table (between 1 to 10 rows/columns, inclusive). In each move, you choose any single cell (R, C) in the grid (R-th row, C-th column) and flip the coins in all cells (r,...

How can be bytecode used for optimizing the execution time of dynamic langauges?

I am interested in some optimization methods or general bytecode designs, which might help speed up execution using VM in comparison to interpretation of an AST. ...

Eliminating extra DBQueries in django by storing the absolute_url

Using Django blogging, I have a template that looks like: <a href="{{ post.get_absolute_url }}">{{ post.title }}</a> This looks innocuous enough, but it ends up generating yet another lookup of the user of the blog post, something that I (in most cases) already know. However that isn't my point. The URL looks like: http://localhost...

Optimizing SQL to determine unique page views per user

Hello, I need to determine if user has already visited a page, for tracking unique page views. I have already implemented some HTTP header cache, but now I need to optimize the SQL queries. The visit is unique, when: pair: page_id + user_id is found in the visit table or pair: page_id + session_id is found or: page_id + [ip + userag...

Factorial -C (Linux)

Please suggest me a more efficient alternative to go about this Program #include <stdio.h> int main(void) { int k, i, t; int arr[100]; //Declaring an array printf("Enter a positive integer: "); scanf("%d", &k); for (i = 0; i < k; i++) { //printf("enter a value %d : ", i); scanf("%d", &arr[i]); ...

How do I prevent NGEN from rebasing my code (negatively affecting performance)?

I simply want to speed up my .NET-base client side app and am considering NGEN-ing the code. Jeffery Richter wrote this warning about ngening code: •Inferior Load-Time Performance (Rebasing). When Windows loads an NGend file, it checks to see if the file loads at its preferred base address. If the file cant load at its pre...

Optimizing away a "while(1);" in C++0x

I have heard and read that C++0x allows an compiler to print "Hello" for the following snippet #include <iostream> int main() { while(1) ; std::cout << "Hello" << std::endl; } It apparently has something to do with threads and optimization capabilities. It looks to me that this can surprise many people though. Does someone...

Making php very fast on shared hosting

Hi all, im using shared hosting and would like to use some kind of opcache library like eaccelerator etc. The problem is i have no permissions to install some of these on server. im looking for some way of optimizing php without having to use PEAR/installing etc. has anyone been able to optimize php on shared hosting and if so, how did...

Mysql query with user-defined-function - why function was called twice?

I have a 1:1 relation between tables Entity and Contact (that corresponds to object 's inherirance). fn_match(id) is UDF which returns boolean and returns true if record matches some special criteria (additional queries inside function). That's a query: select * from Entity a inner join Contact b on a.id = b.id where fn_match(a.i) It ...

What kinds of optimizations does 'volatile' prevent in C++?

Hello, I was looking up the keyword volatile and what it's for, and the answer I got was pretty much: It's used to prevent the compiler from optimizing away code. There were some examples, such as when polling memory-mapped hardware: without volatile the polling loop would be removed as the compiler might recognize that the condit...

Benchmarking Oracle User Procedures/Functions

Hi Guys! I'm thinking of a way on how to benchmark an Oracle procedure. My idea is this, put a logging function on each part of the procedure you wish to benchmark. Store the time it entered that part. Then, create another app (using PHP) to compute the difference between each execution. The PHP app is needed to make it as layman as po...

ComboBox.DataSource assignment taking ages

I have the following code: List<string> list = SomeFunction(); this.myComboBox.DataSource = list; For some reason, the assignment to DataSource is taking a surprising amount of time (about 1.4 seconds), when the list only contains 4 items. Any idea why this is? Edit: SomeFunction() looks in several folders on disk for the existenc...

Getting rid of nested foreach loops when using linq

I am always finding myself creating linq expressions that still use nested foreach loops heavily. Below is a simple example of what I'm talking about, and I'd really appreciate it if someone on here can show me how to condense this low-efficiency code into a single linq expression? The database context (db) has three tables: Blog, Tag, ...

Max number of Activities!

Is there any design guideline on the number of Activities an application could have? If there is a limit, what would be the ideal number of Activities that can be bundled in an Android application. ...

SQLite optimization

I consider to use SQLite in a desktop application to persist my model. I plan to load all data to model classes when the user opens a project and write it again when the user saves it. I will write all data and not just the delta that changed (since it is hard for me to tell). The data may contain thousands of rows which I will need to ...

Is there any difference between 'base' and 'this' when referring to the parent object field, property or method?

Hi, Consider the following code: public class Vehicle { public void StartEngine() { // Code here. } } public class CityBus : Vehicle { public void MoveToLocation(Location location) { ////base.StartEngine(); this.StartEngine(); // Do other stuff to drive the bus to the new location. ...

Why does the JVM still not support tail-call optimization?

Two years after does-the-jvm-prevent-tail-call-optimizations, there seems to be a prototype implementation and MLVM has listed the feature as "proto 80%" for some time now. Is there no active interest from Sun's/Oracle's side in supporting tail calls or is it just that tail calls are "[...] fated to come in second place on every feature...

Optimize SQL query when GROUP BY and ORDER BY expressions are different?

Hello all From the Order By Optimization in Mysql documentation, I quote... In some cases, MySQL cannot use indexes to resolve the ORDER BY, although it still uses indexes to find the rows that match the WHERE clause. These cases include the following: You have different ORDER BY and GROUP BY expressions. Is the...

Python optimization with dfs/bfs searches

Can you see any immediately changes I can do to increase speed and optimization in the script below? We are suppose to write a script which implements dfs/bfs searches to find "ratatosk". Input is which function to use (dfs or bfs), number of nodes in the tree, root node, which node "ratatosk" is in and the rest of the node numbers. ...

What does dotTrace Performance Profiler mean by [Garbage collection]?

What does [Garbage collection] mean in this pic? And the "20 calls" thing? I mean, how can I figure out why GC took so long? Was it collecting a lot of small objects? A single big one? Any hints as to how to optimize this at all? The code in question is: private void DeserializeFrom(SerializationInfo info) { Width = info.GetInt3...