optimization

What is the use of Python's basic optimizations mode? (`python -O`)

Python has a flag -O that you can execute the interpreter with. The option will generate "optimized" bytecode (written to .pyo files), and given twice, it will discard docstrings. From Python's man page: -O Turn on basic optimizations. This changes the filename exten‐ sion for compiled (bytecode) files from .pyc ...

Optimizing MySQL Query

...

Is There A Fast GetToken Routine For Delphi?

In my program, I process millions of strings that have a special character, e.g. "|" to separate tokens within each string. I have a function to return the n'th token, and this is it: function GetTok(const Line: string; const Delim: string; const TokenNum: Byte): string; { LK Feb 12, 2007 - This function has been optimized as best as po...

MySQL Query Select using sub-select takes too long

I noticed something strange while executing a select from 2 tables: SELECT * FROM table_1 WHERE id IN ( SELECT id_element FROM table_2 WHERE column_2=3103); This query took approximatively 242 seconds. But when I executed the subquery SELECT id_element FROM table_2 WHERE column_2=3103 it took less than 0.002s (and resulted 2 ...

java proguard: library doesnt work after optimization

hello, i am optimizing a jar with proguard, but it crashes after optimization. here is my proguard task: <proguard> -injars ${dist}/${jarname} -outjars ${dist}-proguard/${jarname} -target 5 -libraryjars '${java.home}/lib/rt.jar' -dontobfuscate -optimizationpasses ...

Java performance in numerical algorithms

hello again I am curious about performance of Java numerical algorithms, say for example matrix matrix double precision multiplication, using the latest JIT machines as compared for example to hand tuned SSE C++/assembler or Fortran counterparts. I have looked on the web but most of the results come from almost 10 years ago and I under...

Why should methods have a single entry and exit points?

Looking around forums and the web, i have come across the advice that a method should have single entry and exit points. My first question is does the sinlge entry point apply to java. I can't see how a method can have an entry point other than invoking it and passing argumnets to it. The second question is that why only a single return...

Is there a way to improve the speed or efficiency of this lookup? (C/C++)

I have a function I've written to convert from a 64-bit integer to a base 62 string. Originally, I achieved this like so: char* charset = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int charsetLength = strlen(charset); std::string integerToKey(unsigned long long input) { unsigned long long num = input; st...

Rewriting multiple if-statements

I feel like this is a pile of you know what I mean. It works but I feel like I'm way overdoing this in terms of the page lifecycle (load and postbacks) and even the redundancy I have in each of the if statements here. What happens is this: This method is called on very page load (no matter if postback or whatever) If the user submits...

Proper way to handle 'optional' where clause filters in SQL?

Let's say you have a stored procedure, and it takes an optional parameter. You want to use this optional parameter in the SQL query. Typically this is how I've seen it done: SELECT * FROM dbo.MyTableName t1 WHERE t1.ThisField = 'test' AND (@MyOptionalParam IS NULL OR t1.MyField = @MyOptionalParam) This seems to work well, however it c...

How to optimize

I have a method in c# code behind..which needs to be executed 10000+ lines from Assemblies as well as in Child group Methods. My Question is How to optimize it? It is taking more than 40 Seconds Load to 500 Rows in my page my own gridview which is designed by myself. ...

best way to clear contents of .NET's StringBuilder

Hello, I would like to ask what you think is the best way (lasts less / consumes less resources) to clear the contents in order to reuse a StringBuilder. Imagine the following scenario: StringBuilder sb = new StringBuilder(); foreach(var whatever in whateverlist) { sb.Append("{0}", whatever); } //Perform some stuff with sb //Clear s...

Which multilingual web design solution is fastest for the user, if this is indeed an issue?

Context: I'm in the design phase of what I'm hoping will be a big website (lots of traffic, lots of users reading and writing to database). I want to offer this website in the three languages I speak myself (English, French, and by the time I finish the website, I will hopefully have learned enough Spanish to offer that too) Dilemma: ...

Do bitwise operations distribute over addition?

I'm looking at an algorithm I'm trying to optimize, and it's basically a lot of bit twiddling, followed by some additions in a tight feedback. If I could use carry-save addition for the adders, it would really help me speed things up, but I'm not sure if I can distribute the operations over the addition. Specifically if I represent: ...

How to optimize splitting in F# more?

This code is splitting a list in two pieces by a predicate that take a list and return false in the moment of splitting. let split pred ys = let rec split' l r = match r with | [] -> [] | x::xs -> if pred (x::l) then x::(split' (x::l) xs) else [] let res = split' [] ys let last = ys |> Seq.skip (Seq....

MySQL ORDER BY optimisation on range

Hello, I'd like MySQL to use the index to sort these rows. SELECT identity_ID FROM identity WHERE identity_modified > 1257140905 ORDER BY identity_modified However, this is using a filesort for sorting (undesirable). Now, if I leave off the ORDER BY clause here, the rows come out sorted simply as a consequence of using the in...

Very fast memcpy for image processing?

I am doing image processing in C that requires copying large chunks of data around memory - the source and destination never overlap. What is the absolute fastest way to do this on the x86 platform using GCC (where SSE, SSE2 but NOT SSE3 are available)? I expect the solution will either be in assembly or using GCC intrinsics? I found...

JavaScript: document.getElementById slow performance?

Hi I repetitively use document.getElementById a lot on common CSS elements. Would there be a significant performance gain if I created a global array to store all of my document.getElementById element in instead of refetching the element each time? Example, instead of: document.getElementById("desc").setAttribute("href", "#"); docume...

F# Code Optimization for Left Leaning Red Black Tree

I've been working on porting a C# implementation of a LLRBT to F# and I now have it running correctly. My question is how would I go about optimizing this? Some ideas I have Using a Discriminated Union for Node to remove the use of null Remove getters and setters you cant have a null attribute and a struct at the same time Full ...

MySQL Join Optimization

Can you please help me optimize this query. I use this query to get a list of friends along with their details and their status. It takes about 0.08 secs to process this on a Athlon X2 6000 I cant use materizlized view as well because this is frequently changing. SELECT p.userid, p.firstname, p.lastname, p.gender, p.dob, x.relationship...