Archive for the ‘C++’ Category

GCC Vs. LLVM – Simple Test Code Optimizations

As a companion piece to this test suite on Phoronix I took the following *very simple* code and ran it though GCC 4.6 (Fedora 15) and the Clang/LLVM 2.8 Suite to check performance and various optimizations being performed:

#include <stdio.h>
#include <stdlib.h>

int test_noRef(int value)
{
	return value + 1;
}

int test_ref(int &value){
	return value += 1;
}

int main(int argc, char *argv[]){

	int t = 1;

	for(int i = 0; i < 100000000; i++){
		//t = test_noRef(t);
		test_ref(t);
	}

	// final result = n loops + 1
	printf("%d\n", t);

}

Read More

Benchmarks: JavaScript vs. PHP vs. HPHP vs C++

Just a quick spattering of some benchmarks I ran while testing a program I’m developing internally.

The first three are of the fannkuch benchmark found on the sunspider test site, only ported over to C++ and PHP in addition to the JS version. The browser used for all tests was Firefox 5.

The HPHP listing is a compiled Hip Hop PHP version, which is interesting as it shows the relative difference between it and vanilla PHP.

The last item, Benchmark.php, is the same benchmark file you’ll find in a PHP source download.

See the full benchmarks after the jump!

Read More

QT SDK 1.1.2 -Install The QODBC Driver

In the most recent versions of the Qt SDK it appears as if default support for all databases except SQLite has been removed.

The Qt documentation provides a short write-up on how to re-enable this driver, but it leaves out some important details.

To enable support for the QODBC driver follow these steps:

1. From the Qt Creator Application Launch Start Updater:

Continued after the jump…

Read More

Sunspider Benchmark in C++

The Sunspider JavaScript Benchmark is a popular test of Web Browser performance.

As great as the newest browsers are I though it would be interesting to take a random test and port it to C++ for the sake of comparison.

I decided the rather short fannkuch test was a good candidate. The results:

Not surprisingly the C++ version is 18x faster than Firefox and 8x faster than Chrome. For the curious, the ported C++ code is after the jump.

I should mention one thing changed from the stock Sunspider site (e.g., the link above), is the number of iterations was upped from 8 to 10. At 8 iterations the C++ version was sub-millisecond, meaning I’d have had to roll a custom assembly timer to get a benchmark value. That said, when we lower the iterations down to 9, the stack heavy algorithm starts to benefit the browsers more, with Chrome coming in only 3 times slower and Firefox 11.

Lower the iteration count to the “stock” 8 and Firefox actually catches up to Chrome, with both browsers reporting ~21ms. Interesting.

Read More

SSE And Inline Assembly Example

In previous posts we’ve covered Inline Assembly and SSE Intrinsics coding.

In this post we’ll merge these concepts by creating a version of the CMYK to RGB conversion code strictly in raw SSE and assembly. The upshot is you’ll see how we can take existing, real-world C++ code and use GCC’s Extended Assembly syntax to interweave raw assembly code for potential performance gains.

This means this tutorial is not just about extended assembly or sse coding, it’s about using both in a real-world application. We’ll learn many concepts including data retrieval, loop processing, SSE processor instructions, floating point number representation, and much more!

Read More

Aesop – A Hip Hop PHP UI

Download the Complete (and free, as in open source free) Aesop + HPHP files from right here.

PHP is my favorite language, bare none. It’s simple, elegant, and fun to use. Problem is, for highly trafficked sites it’s a touch slow and can be quite memory hungry. If you’re Facebook this can lead to problems, which is why they invented Hip Hop PHP (HPHP), a collection of tools and technology that turns our slow and hungry PHP code into lean and mean C++.

Ok, So Just How Fast Is It?

As a quick comparison I created a simple FormBoss form and ran Apache Bench (ab from the command line), to get a sense of the speed difference between Apache 2.2 and HPHP.

The top two tests are when running our simple .php files, the bottom test is when serving a simple 62 byte .xml file with 100 concurrent users:

**It’s important to note these numbers will be lower when running though a network and calling a database. Also, while other servers like Cherokee can be twice as fast as Apache, HPHP is still nearly twice as fast again.

So yes, qualifications aside, HPHP is very fast indeed.

Sure these numbers are fantastic, but using HPHP means compiling the source from scratch and then using a series of command-line switches to run and manage the compiled PHP code.

No longer–In my spare time I’ve created and now released an open-source front-end UI to HPHP.

Read on to learn more, or just download the files!

Read More

Connecting to an MSSQL Database in Qt

In this post we’ll review code for connecting a 32-bit Qt application to an SQL Server 2008 R2 instance running on 64-bit Windows 7.

Read More

C++ Understanding Pointers In Assembly

One of the joys of working with C++ is the ability to get ‘down to the metal’ and talk to the hardware directly. Not only can this direct-access improve performance, as a pedagogical tool it allows us to peek under the hood at raw assembly high-level code produces. This can have the effect of demystifying many aspects of programming, as while high-level languages make coding more efficient, they hide much of how things actually work.

One such example of this is with pointers. In C++ we learn that pointers are objects that hold a reference to some other objects memory location. We’re taught to dereference and pass pointers to functions, how to avoid stray and dangling pointers, and if we’re former Java developers, what all those Null Pointer errors actually meant.

Of course despite this deeper understanding even C++ hides what pointers truly are and how they’re represented and manipulated in hardware.

In this post then I want to quickly look at pointers from the standpoint of assembly language so next time you use one, you’ll have a better idea of what one actually is at the most basic level. This may even make learning what pointers are easier for newcomers.

I also, of course, want to talk performance.

Read More

SSE Intrinsics Tutorial

UPDATE: For those interested, I’ve created a full-on assembly/SSE version here.

SSE SIMD Programming is a fascinating subject, but also one that can be a bit difficult to approach. In this post I’m going to create a SIMD version on my RGB->CMYK algorithm, and in the process, show a bunch of handy tricks for working with SIMD.

This post deals with some of the problems and challenges we face when implementing SIMD code, paying close attention to intrinsics, basic SIMD code setup, and buffer type conversion.

Read More

GCC Inline Assembly Loop Structures

While I’ve covered basic assembly before, I wanted to quick touch on the idea of implementing simple control flow techniques. GCC of course allows for this in the extended syntax mode, but finding good documentation with examples is hard. The point of this post then is to show a few simple examples of writing control flow code, as well as point out a few of the more subtle points.

Read More