optimization

Regex optimisation - escaping ampersands in java

I need to replace all & in a String that isnt part of a HTML entity. So that the String "This & entites > & <" will return "This & entites > & <" And I've come up with this regex-pattern: "&[a-zA-Z0-9]{2,7};" which works fine. But I'm not very skilled in regex, and when I test the speed over 100k iterations, it uses...

Is building separate .swc allow a faster loading of the application ?

Our application is a bit slow to load at startup, i'm wandering myself if a sepation of the module of the application in several swc will decrease the loading time( grosso modo : a module = a "page" ) ...

Queue SQL implementation with a single query.

I have an SQL table that looks like: TABLE QUEUE ID DATA POSITION Field POSITION holds the potition of the record relative to a Queue. So, it can be: 0 not in any position (not queued). 1 first in the queue (next in line). > 1 the position in the queue. I need a (MS) SQL query that will move the queue up one position...

How can I optimally update a single property in an object using Hibernate?

I have an object: public class Data { private long id; private long referenceCount; private Blob dataCache; /* getters and setters for the above */ } Corresponding to this is a mapping: <hibernate-mapping> <class name=Data" table=DATA"> <id name=id" type="long"> <column name...

Optimization suggestions for sql server table

I have a table containing user input which needs to be optimized. I have some ideas about how to solve this but i would really appreciate your input on this. The table that needs optimization is called Value in the structure below. All tables mentioned below has integer primary keys called Id. Specs: Ms Sql Server 2008, Linq2Sql, asp.net...

Best practice for keeping denormalized schema up to date?

I'm creating a game with points for doing little things, so I have a schema as such: create table points ( id int, points int, reason varchar(10) ) and to get the number of points a user has is trivial: select sum(points) as total from points where id = ? however, performance has become more and more of an issue as the points...

sql userid + name + profile optimize question

Chances are i will need to do a lot of userid->username lookups. So i was thinking, instead of having a table like the below userid int PK username text userpass_salthash int user_someopt1 int user_sig text to have it broken up as the below //table1 userid int PK username text //table2 userid int //fk userpass_salthash int user_some...

How can I improve this square root method?

I know this sounds like a homework assignment, but it isn't. Lately I've been interested in algorithms used to perform certain mathematical operations, such as sine, square root, etc. At the moment, I'm trying to write the Babylonian method of computing square roots in C#. So far, I have this: public static double SquareRoot(double x) ...

How large structs can be passed by value efficiently?

The rule of thumb is that it is okay to pass small structs by value and larger ones should be done pointers. My question is where exactly is this cutoff point? How large can the structures be before you are better off passing them by pointer. I know this will vary between platforms, but I assume some rough estimates could be given. A ...

Optimizing a simple search algorithm

I have been playing around a bit with a fairly simple, home-made search engine, and I'm now twiddling with some relevancy sorting code. It's not very pretty, but I'm not very good when it comes to clever algorithms, so I was hoping I could get some advice :) Basically, I want each search result to get scoring based on how many words ma...

Why in this example using floats makes me go 2x slower than with doubles?

I've been doing some profiling lately and I've encountered one case which is driving me nuts. The following is a piece of unsafe C# code which basically copies a source sample buffer to a target buffer with a different sample rate. As it is now, it takes up ~0.17% of the total processing time per frame. What I don't get is that if I use ...

Instance Size in C#

Is there any way to get the size of an instance (or the class I don't mind) in C#? For example, I know in Delphi every object has a pointer to the Virtual Method Table of the class, a pointer for each interface it implements plus of course the fields of the class. According to this basic object size is 12 bytes in x86, but, is there an...

SQL (any) Request for insight on a query optimization

I have a particularly slow query due to the vast amount of information being joined together. However I needed to add a where clause in the shape of id in (select id from table). I want to know if there is any gain from the following, and more pressing, will it even give the desired results. select a.* from a where a.id in (select id...

Difference between n = 0 and n = n - n

When I read this question I remembered someone once telling me (many years ago) that from an assembler-point-of-view, these two operations are very different: n = 0; n = n - n; Is this true, and if it is, why is it so? EDIT: As pointed out by some replies, I guess this would be fairly easy for a compiler to optimize into the same th...

Compile Flex application without debug? Optimisation options for flex compiler?

I have created a simple test application with the following code var i : int; for (i=0; i<3000000; i++){ trace(i); } When I run the application, it's very slow to load, which means the "trace" is running. I check the flash player by right-clicking, the debugger option is not enable. So I wonder if there is an option to put in com...

Memory / Optimization concern

I'm working at a complex script which could be processing upto 500,000 records. Here's my question. Basically my code will parse a text file to get each of those 500,000 or so records. Each record will have a category, my code will need to check if a new record in the categories table had been created for that category during that parti...

Cost of common operations for C#?

In Code Complete 2 (page 601 and 602) there is a table of "Cost of Common Operations". The baseline operation integer assignment is given a value 1 and then the relative time for common operations is listed for Java and C++. For example: C++ Java Integer assignment 1 1...

Return value optimization in VC2008

Is there other technique like RVO (return value optimization) or NRVO (named return value optimization) that can be use with VC2008? ...

MySQL speed optimization on a table with many rows : what is the best way to handle it ?

Hi, I'm developping a chat application. I want to keep everything logged into a table (i.e. "who said what and when"). I hope that in a near future I'll have thousands of rows. I was wondering : what is the best way to optimize the table, knowing that I'll do often rows insertion and sometimes group reading (i.e. showing an entire conver...

Why does Java code generated to perform an operation run more slowly than an "interpreter loop"?

I have some Java code which performs bitwise operations on a BitSet. I have a list of operations and can "interpret" them by looping over them, but it's important to me that I can perform these operations as quickly as possible, so I've been trying to dynamically generate code to apply them. I generate Java source to perform the operat...