Random 14 Dec 2013 01:26:51

Thought Experiment: Population

Imagine a community of N people following these three rules:

  1. Every day, at most 1 person is born
  2. Every day, at least 1 person dies
  3. Over time, the population does not decrease (tomorrow, N must be ≥ the N of today)

What is the minimum value possible for N to start as?

What other social or biological constraints you choose to enforce is up to you, but it is probably most fun if your initial simulation follows modern norms. Then you can skew the variables to see how bizarre a community you can create.

Continue Reading »

PHP 26 Apr 2012 17:00:00

I Like PHP

While there is no doubt PHP is broken beyond repair, it does have a few virtues that keeps it as one of my first choices when writing certain kind of web frontends and minor tools.

There is a huge laundry list of how PHP is broken at “PHP a fractal of bad design“, which I almost entirely agree with. What I will do here is point out the few things on that list that I do not agree with, and why.


Continue Reading »

C++ 25 Feb 2012 13:19:21

C++ vector vs realloc()

A comparison of how many reallocations a worse case poorly coded use of realloc() does, compared to just using std::vector. 10000000 integers are added to the containers one-by-one. Clearly you would never abuse realloc() like this in real code, but it’s interesting nonetheless. Idea from sacrebleu at Freenode’s ##C++.

The full source is available in svn as a CMake project for easy cross-platform testing. Primary source vector-realloc.cpp

Allocs / OSstd::vectorrealloc()
Windows 7409526
Linux: Arch24367
Linux: Fedora 1024438
Mac OS X2431
  • Mac OS X: OS X 10.7.3, 2.3 GHz Core i5, 8 GiB RAM. XCode 4.3, clang++ 3.1 -std=c++0x -stdlib=libc++ -O3.
  • Windows 7: 64 bit, 1.60GHz Core i7 Q720, 8 GiB RAM. MSVC++ 2010 _SECURE_SCL=0
  • Linux: Arch: VirtualBox on the Windows machine, VT-x, Arch Linux, kernel 3.2.7-1-ARCH x86_64, 1 GiB RAM. GNU g++ 4.6.2 -std=c++0x -O3
  • Linux: Fedora 10: Fedora 10, kernel 2.6.27 x86_64, 2.66GHz Xeon, 8 GiB RAM. GNU g++ 4.4.1 -O3

C++ 20 Feb 2012 16:12:15

C++ Set Performance 2

(Old version from 2010-04-02)

A performance comparison of the speed of operations on the various set implementations used in C++. There are 16383 unique elements across which 1000000 insert, lookup, iterate, and erase operations are performed.

The raw tick numbers are shown and table sorting is enabled so you can compare for yourself. Just be aware that the Mac OS X, Linux, and Windows numbers cannot be compared against each other.

The full source is available in svn as a CMake project for easy cross-platform testing.

Sources


Continue Reading »

C++ 31 Aug 2011 22:27:06

C++ Include Speed

A performance benchmark of which include guard method is faster. Test times the compilation of a main.cpp that includes 10000 files 3 times each.

The tested methods are:

  • #pragma once followed by #ifndef
  • #ifndef followed by #pragma once
  • Only #pragma once
  • Only #ifndef
  • External #ifndef

Sources for the test is at inc.tar.gz, but it’s just 5×10000 files.

The compilers are Microsoft Visual C++ 2010, GNU g++ 4.6.1, and LLVM clang++ 2.9.


Continue Reading »

« Previous PageNext Page »