performance

What is the fastest way to decide if a digit appears in a string?

This simple solution popped into my mind quickly. #include <ctype.h> int digit_exists_in ( const char *s ) { while (*s) { if (isdigit(*s)) { return 1; } else { s++; } } return 0; } int main(void) { int foundDigit = digit_exists_in("abcdefg...

Performance/Style Question About Returning from a Method/Function

I found some code like this in a project I'm working on public SqlDataReader SomeMethod(int someParam) { // ... some code goes here SqlDataReader dataReader = m_command.ExecuteReader(CommandBehavior.CloseConnection); return dataReader; } I was wondering what is better, the original or below public SqlDataReader Some...

How do I dynamically load Google Analytics JavaScript?

Without using any other JS frameworks (dojo, jquery, etc), how would I dynamically load Google Analytic's javascript to be used on a web page for web-tracking? The typical appropriate to dynamically loading JS is to do the following: var gaJs = document.createElement("script"); gaJs.type = "text/javascript"; gaJs.src = "http://www.goog...

How is pattern matching in Scala implemented at bytecode level?

How is pattern matching in Scala implemented at bytecode level? Is it like a series of if (x instanceof Foo) constructs, or something else? What are its performance implications? For example, given the following code (from Scala By Example pages 46-48), how would the equivalent Java code for the eval method look like? abstract class Ex...

strict aliasing

in C, what exactly are the performance benefits that come with observing strict aliasing? ...

Can anyone help with this problem I am having with finditer in python?

Hi, I have a somewhat complex regular expression which I'm trying to match against a long string (65,535 characters). I'm looking for multiple occurrences of the re in the string, and so am using finditer. It works, but for some reason it hangs after identifying the first few occurrences. Does anyone know why this might be? Here's the c...

Declaring an Index as unique in SQL Server

If I know an index will have unique values, how will it affect performance on inserts or selects if I declare it as such. If the optimiser knows the index is unique how will that affect the query plan? I understand that specifying uniquenes can serve to preserve integrity, but leaving that discussion aside for the moment, what are the...

Any hard data on GC vs explicit memory management performance?

I recently read the excellent article "The Transactional Memory / Garbage Collection Analogy" by Dan Grossman. One sentence really caught my attention: In theory, garbage collection can improve performance by increasing spatial locality (due to object-relocation), but in practice we pay a moderate performance cost for softw...

Adding a column efficently in SQL Server

I want to add an integer column to a table with a large number of rows and many indexes (Its a data warehouse Fact Table). To keep the row width as narrow as possible all the columns in this table are defined as not null. So I want the new column to be not null with a default of zero. From experience adding this column will take some t...

Java PriorityQueue removal of arbitrary elements performance

Say I have a java PriorityQueue (which java implements as a heap) that I iterate over to remove elements based on some criteria: PriorityQueue q = new PriorityQueue(); ... Iterator it = q.iterator(); while(it.hasNext()){ if( someCriterion(it.next()) ) it.remove(); } How long does each remove() operation take? I'm not sure ...

Whats the easiest and fastest way to measure HD performance using Python?

I need to measure the performance of a hard disk using python. What is the best/fastest/shortest/easiest approach to do it? It doesn't have to be overly accurate, just a ballpark value. My actual goal is to write a small utility which will adjust the postgres settings to the best configuration for the given hardware. My naive approach ...

Performance Considerations Using Multiple Layers of Generators in Python?

Are there any performance considerations for using a lot of generators chained together, as opposed to just a single generator. For example: def A(self, items): for item in self.AB(items): if object.A(): yield item def AB(self, items): for object in self.ABC(objects): if object.A() or object.B(): ...

.Net Performance/Event Monitoring

I'm looking to do both event tracking/monitoring from applications (i.e. real-time business metrics being emit from applications) and general performance monitoring (i.e. CPU usage, mem Usage etc...). I'd like to be able to have the metrics collected to a central location where they could be reported on etc... Also I'd like to be able to...

What is the right solution for a high-availability authorization service?

I work for a software shop, which has an in house predictive dialer product, and we need to implement a solution to obey to the DO-NOT-CALL lists. Basically, I have a database with the customers/prospective customers that I need to call, and another database with the phone numbers I can't call. As the system is a predictive dialer, bas...

Performance issue: comparing to String.Format

A while back a post by Jon Skeet planted the idea in my head of building a CompiledFormatter class, for using in a loop instead of String.Format(). The idea is that the portion of a call to String.Format() spent parsing the format string is overhead. We should be able to improve performance by moving that code outside of the loop. The...

How does the IN predicate work in SQL?

After prepairing an answer for this question I found I couldn't verify my answer. In my first programming job I was told that a query within the IN () predicate gets executed for every row contained in the parent query, and therefore using IN should be avoided. For example, given the query: SELECT count(*) FROM Table1 WHERE Table1Id N...

rails ruby-prof and benchmark testing

I'm running Rails 2.2.2. I've read a few articles about ruby-prof and profiling a rails app. And I'm confused as to how things are really working. I was originally using this tutorial http://snippets.aktagon.com/snippets/255-How-to-profile-your-Rails-and-Ruby-applications-with-ruby-prof to profile my app, and it works. This involves...

HTML to PDF - Bad performance

I´m using ExpertPDF (library for .NET C#) for converting HTML to PDF and my problem is that it takes a lot of time to do this. Are there any customizations that will improve the conversion? The HTML-page contains table-data with just a few images, so it is not that complex. Have anyone else ever experienced this problem, or do you re...

Performance of passing lots of value types in parameters

I am currently reading C# in Depth by Jon Skeet and have been reading about value and reference types. It got me thinking about the cost of using value types as method parameters due to that value being copied when passed. While this cost is not much when considering integers, what if those value parameters were strings which got passed...

Unexpected performance results comparing INT to BIGINT for IDENTITY columns.

I have been asked to perform a performance test using SQL Server 2008. As part of this, I am comparing the speed of IDENTITY columns as PKs using INTs and BIGINTs. I have a simple routine to create 100,000 rows for each type and time the insert speed. The script looks like this: SET NOCOUNT ON CREATE TABLE TestData ( PK INT IDENTI...