Interactive demos require Javascript. Anything else works.

Simple Ajax

posted by Stephan Brumme

Interactive Web Sites

Ajax is the technology upon which pretty much every modern interactive website is build (except for these weird Flash sites). Professional web sites use large frameworks like jQuery that wrap the details of Ajax in a nice programming interface. That's perfectly fine but total overkill for a small blog like this.

Live Demo

This DNS-to-IP resolver returns the IPv4 address of any domain. It may take up to 3 seconds to get a result.

Enter a domain name: => IP:

Have a look at the sorting algorithm live demo which is based on Ajax, too.

(read more ...)

Sparklines

posted by Stephan Brumme

Why sparklines ?

When I started my realtime logfile analysis website status.stephan-brumme.com, I was looking for a way to display activities, such as traffic or hits, in compact yet intuitive way.
A primary concern was that standard diagrams just take too much space. I gradually reduced their size until they had about the same height as the surrounding text:

214x83 pixels: 214x83 pixels 107x42 pixels: 107x42 pixels 54x21 pixels: 54x21 pixels 27x11 pixels: 27x11 pixels

It's impossible to have any readable legend in the smallest diagram - and I don't really need it. All I want to know is: is a lot going on ? or is my server pretty much dead ? The small diagram fits these needs.

I wasn't the first to come up with the idea of diagrams scaled down to the size of text. Edward Tufte published some of the most impressive books about information visualization and coined the term sparklines.

There is a huge variaties of sparklines, not only the classic line chart. I wanted something more computer-like and ended up with this drawing style: random sparkline.

Live Demo

Create some of sparklines on-the-fly: => live demo sparkline

(read more ...)

smallpt - Global Illumination in Javascript

posted by Stephan Brumme

smallpt

Kevin Beason published a C++ Monte Carlo path tracer that is just 99 lines long short. Despite this limit the code supports the most common materials: diffuse and specular reflection as well as refraction.
Sven Klose, apparently from Germany like me, ported the code to Javascript but his website is down for quite some time now. I couldn't find his source code anywhere on the internet so I converted the code from C++ to Javascript again and compared how fast it runs on the most important web browsers.

Live Demo

You need a web browser with HTML5-canvas support. It's a standard feature of all modern browsers and you are typically fine even with slightly older versions of Chrome, Opera, Safari or Firefox. However, Internet Explorer needs to be version 9+ which is not available for the still popular Windows XP.

passes:

original size (64x64):

8x zoomed (512x512):
Oops, your browser doesn't support HTML5 canvas ...
(read more ...)

Multi-Core Sorting

posted by Stephan Brumme

The old-fashioned way

Most traditional sorting algorithms (I already blogged about their STL-compatible versions) work in a serial manner and are perfectly suited for single-core machines.
My current computer has a Intel Core i7 860 CPU which comes with 4 cores and hyperthreading, giving me a total of 8 logical cores. That means, CPU utilization with traditional sorting algorithms (i.e. only able to run on one 1 out of 8 cores) cannot exceed 12.5%. That sucks.

OpenMP

Luckily, the GCC team made parallelized versions of pretty all important STL algorithms available. They still call their implementation experimental but I haven't had any problems so far.
Everything is based on OpenMP which has been supported since GCC 4.2. Visual C++ and Intel C++ support OpenMP as well but I haven't tested GCC's library with these commercial compilers yet.

How to use it

There are two ways to switch to GCC's parallel mode:
  1. link against -D_GLIBCXX_PARALLEL or
  2. use the __gnu_parallel namespace
In both cases you have to enable compiler switch -fopenmp and include parallel/algorithm.
hide // g++ -O3 -fopenmp -march=native parallelSort.cpp -o parallelSort #include <algorithm> std::sort(data.begin(), data.end()); #include <parallel/algorithm> __gnu_parallel::sort(data.begin(), data.end());

(read more ...)

CLein

posted by Stephan Brumme

What is CLein ?

CLein is a tiny, portable freeware program which displays all relevant information about the OpenCL drivers installed on your system.
It contains a small benchmark to compare the computing power of your host CPU and your OpenCL device(s), too.

If you have no idea what OpenCL is then read this article on Wikipedia.

(read more ...)

browse through all postings:
newer stuff:

2021/Jun/30   Length-Limited Prefix Codes
2020/Apr/13   smalLZ4 - optimal LZ4 compression
2019/Jun/17   toojpeg - a JPEG encoder in a single C++ file
2018/Oct/15   flexiGIF - lossless GIF/LZW optimization
2016/Aug/04   xxHash - a hash algorithm as fast as memcpy
2015/Aug/11   Tiny Regular Expression Matcher
2015/Feb/04   Fast CRC32
2014/Aug/25   Practical String Searching
2014/Aug/19   The Mersenne Twister Pseudo Random Number Generator
2014/Jul/11   Parallel Sieve of Eratosthenes
2014/Jun/23   Windows and Linux Code Timing
2014/Jun/14   Portable C++ Hashing Library
2014/Feb/27   Sorting STL Containers
2013/Sep/18   Portable Memory Mapping C++ Class
2013/May/03   Testing Endian Aware Code
2013/Apr/24   Software License
2013/Feb/15   Read-Only Git Access Available
2011/Dec/05   Fowler-Noll-Vo Hash (FNV1a)
2011/Dec/01   Drawing Antialiased Circles and Ellipses
2011/Nov/27   Uncompressing DEFLATE Data
2011/Nov/23   Streaming MPEG-4 Movies From Your Own Server
2011/Nov/08   Binary Search Revisited
2011/Oct/20   Reverse MD5 Hash
2011/Oct/17   Windows 7 Screenshots
2011/Oct/16   Hide Strings In Your Executable
2011/Oct/11   Generate QR Codes With PHP and Google Charts API
2011/Oct/02   Feed.rss and Sitemap.xml
2011/Sep/28   My Experiences with AdSense
2011/Sep/27   Emulating MemCache in Pure PHP
homepage