optimization

Improve performance of a regexp

My software allows users to use regexp to prepare files. I am in the process of adding a default regexp library with common expressions that can be re-used to prepare a variety of formats. One common task is to remove crlf in specific parts of the files, but not in others. For instance, this: <TU>Lorem Ipsum</TU> <SOURCE>T...

Finding closest neighbour using optimized Levenshtein Algorithm

I recently posted a question about optimizing the algorithm to compute the Levenshtein Distance, and the replies lead me to the Wikipedia article on Levenshtein Distance. The article mentioned that if there is a bound k on the maximum distance a possible result can be from the given query, then the running time can be reduced from O(mn)...

Passing a method call and its parameter to a different method

I am using an external automation library with bunch of APIs with either 1 or 2 parameters which randomly throws TargetInvocationException. Calling these APIs second or third time usually works. I therefore created two helper methods to encapsulate the multiple retry logic //Original API calls bool result1 = Foo1(true); int result2 = Fo...

How to improve SQL Server query containing nested sub query

I was given this SQL query by my boss and told to improve/optimize it DECLARE @pol_0 int, @pol_1 int, @pol_2 int, @pol_3 int, @pol_4 int, @pol_5plus int, @peril_0 int, @peril_1 int, @peril_2 int, @peril_3 int, @peril_4 int, @peril_5plus int, @loc_1 int, @loc_2_10 int, @loc_11_100 int, @loc_101_1000 int, @loc_1001_5000 int, @loc_...

FP-intensive hyperthreading performance on latest Xeons

We have recently purchased a dual Intel X5650 workstation to run a floating-point intensive simulation, under Ubuntu 10.04. Each X5650 has 6 cores, so there are 12 cores in total. The code is trivially parallel, so I have been running it mostly with 12 threads, and observing approximately "1200%" processor utilization through "top". Hy...

XML reading optimization .NET

Here's what I've got thus far: Dim xpDoc As New XPathDocument(strXmlUrl & strXmlInfo(0) & "?xml=1") Dim xpNav As XPathNavigator = xpDoc.CreateNavigator() Dim xpExpression(9) As XPathExpression Dim xpIter(9) As XPathNodeIterator xpExpression(0) = xpNav.Compile("/profile/steamID64") 'etc.. up to 9 For i = 0 To 9 xpIter(i) = ...

regular expression very slow on fail

I've a regular expression that should validate if a string is composed by space-delimited strings. The regular expression works well (ok it allows a empty space in the end ... but that's not he problem) but takes too long when the validation fails. The regular expression is the following: /^(([\w\-]+)( )?){0,}$/ When trying to valida...

Android server load advice

Hi, I'd like a bit of advice on how to retrieve, process and store data. I'm building an app which gets finds the nearest laser tag site to where you are. The adderss data is stored (due to some bad design) in one field in an external database, with it's country coming from another table (told you it was a bad design). I may change whe...

UPDATE FROM with a JOIN (Large Table Performance) Postgresql?

I'm trying to get the following query to execute at a reasonable performance: UPDATE order_item_imprint SET item_new_id = oi.item_new_id FROM order_item oi INNER JOIN order_item_imprint oii ON oi.item_number = oii.item_id Currently, it doesn't complete within 8 days so we killed it. The query explaination is as f...

Does over-using function calls affect performance? Specifically in Fortran

I habitually write code with lots of functions, I find it makes it clearer. But now I'm writing some code in Fortran which needs to be very efficient, and I'm wondering whether over-using functions will slow it down, or whether the compiler will work out what's going on and optimise? I know in Java/Python etc each function is an object,...

Optimal MySQL temporary tables (memory tables) configuration?

Hello, excuse my english First of all, I am new to optimizing mysql. The fact is that I have in my web application (around 400 queries per second), a query that uses a GROUP BY that i can´t avoid and that is the cause of creating temporary tables. My configuration was: max_heap_table_size = 16M tmp_table_size = 32M The result: temp ...

Search Query Optimization

I haven't ever dug into cleaning/reformatting search queries too much in the past, at least not more than general security things like preventing sql injection. I am realizing that I should be implementing keywords like AND, OR, NOT, etc... and doing things like clearing punctuation such as apostrophes, hyphens, etc... As when a user ty...

Min Max-Matching Problem

I have a matching problem and I don't know how to solve it: Given a complete bipartite graph (A, B). Each node a_i in A, has two states: s(a_i)=0 or s(a_i)=1 Weighted edges are declared as: w(a_i, b_j, s(a_i)) Fixing a configuration for the states, the problem becomes a max-matching. The goal is to find the configuration with minimum...

SQL Server Select query optimization

Hi, I am looking at some feature which will enable me to partition tables horizontally, i.e. the context of me referring to a table is only a sub-set of the entire set of records in a table. This could be a typical scenario in a SaaS model since data of one account is not of significance to another. Let us say, there is a...

How to optimize a recursive algorithm to not repeat itself?

After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same area...

How can memoization be applied to this algorithm?

After finding the difflib.SequenceMatcher class in Python's standard library to be unsuitable for my needs, a generic "diff"-ing module was written to solve a problem space. After having several months to think more about what it is doing, the recursive algorithm appears to be searching more than in needs to by re-searching the same area...

Is repeatedly calling size() on a container (during loop) bad?

For efficiency reasons, I always avoid writing loops like this: for(std::size_t i = 0; i < vec.size(); ++i) { ... } where vec is an STL container. Instead, I either do const std::size_t vec_size = vec.size(); for(std::size_t i = 0; i < vec_size; ++i) { ... } or use the container iterators. But how bad is the first solution really...

Optimizing Rails loading for maintenance scripts

Hello, I wrote a script that does maintenance tasks for a rails application. The script uses a class that uses models defined in the application. Just an example, let's say application defines model User, and my class (used within the script), sends messages to it, like User.find id. I am looking for ways to optimize this script, becau...

Ways to improve efficiency of C# code

Hi all, Like most of us, I am a big fan of improving efficiency of code. So much so that I would rather choose fast-executing dirty code over something which might be more elegant or clean, but slower. Fortunately for all of us, in most cases, the faster and more efficient solutions are also the cleaner and the most elegant ones. I u...

how can i optimize this query taking 30 seconds for 1746 rows

query: SELECT A.USER_ID, A.ROLE_ID, C.SUBGROUP, MAX(A.STATUS_ID) FROM USER_ROLE A, USER B, ROLE C WHERE A.ROLE_ID = C.ROLE_ID AND C.GROUP_ID = 3 AND A.USER_ID = B.USER_ID AND B.TEMPLATE_IND = 'N' AND B.ONAP_PARTCODE IS NULL ...