Skip to content

Instantly share code, notes, and snippets.

@nlguillemot
nlguillemot / SConstruct
Created May 28, 2012 03:44
Kinect + Irrlicht prototype
env = Environment()
linked_libs = ['Irrlicht', 'GL', 'freenect']
cpp_flags = ['-std=c++0x']
env.Append(LIBS = linked_libs)
if ARGUMENTS.get("debug",0):
cpp_flags += ['-g']
env.Append(CPPFLAGS = ' '.join(cpp_flags))
@nlguillemot
nlguillemot / O0tmp.s
Created June 20, 2012 05:30
label weirdness cross-compiled with linux arm gcc
.arch armv4t
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 18, 4
@nlguillemot
nlguillemot / CSC230Assignment3.s
Created June 20, 2012 06:01
CSC 230 Assignment 3 - Treadmill
@ CSC230 Spring 2012 -- Treadmill program
@ Author: Nicolas Guillemot
@ Student ID number: V00695164
@ Global constants for physics
@ default value for weight
.equ DFT_WEIGHT, 100 @ lbs
@ minimum value for weight (see WeightMax for maximum)
.equ WEIGHT_MIN, 50 @ lbs
@ default value for target speed
@nlguillemot
nlguillemot / MillionItemList.cpp
Created June 25, 2012 00:57
Comparison of performance of adding elements to preallocated containers in c++11
#include <vector>
#include <list>
#include <iostream>
#include <ctime>
// FIXME: v(1000000) creates a vector of 1000000 elements. At the end of the function there are 2000000 elements. Instead, it should be constructed empty and then v.reserve(1000000) should be called just after.
void createPreallocatedMillionVector()
{
std::vector<int> v(1000000);
@nlguillemot
nlguillemot / output with g -stdc0x -O2
Created July 1, 2012 04:06
Comparison of performance of adding elements to containers in C++
Vector took 0.18 seconds.
Preallocated Vector took 0.1 seconds.
Back pushed List took 1.38 seconds.
Front pushed List took 1 seconds.
Front pushed Pool allocated list took 0.67 seconds.
In other words,
Preallocating a vector makes it ~200% faster than not preallocating
Pushing to the front makes it ~150% faster than pushing to the back
Pushing to the front and using a pool allocator makes it ~200% faster than pushing to the back
@nlguillemot
nlguillemot / HashedString.hpp
Created July 14, 2012 18:50
better HashedString class
#ifndef HASHEDSTRING_HPP_INCLUDED
#define HASHEDSTRING_HPP_INCLUDED
#include <irrlicht/irrTypes.h>
// if HASHEDSTRING_USE_CONSTEXPR is defined, a recursive constexpr hashing algorithm will be used.
// otherwise, an iterative runtime hashing algorithm will be used.
#define HASHEDSTRING_USE_CONSTEXPR
// do not touch this block of preprocessor.
@nlguillemot
nlguillemot / HashedString.cpp
Created July 17, 2012 19:27
Compile-time hashed strings with unit test
#include <cstdint>
// if HASHEDSTRING_USE_CONSTEXPR is defined, a recursive constexpr hashing algorithm will be used.
// otherwise, an iterative runtime hashing algorithm will be used.
#define HASHEDSTRING_USE_CONSTEXPR
// do not touch this block of preprocessor.
#ifdef HASHEDSTRING_USE_CONSTEXPR
#define HASHEDSTRING_CONSTEXPR_IMPL constexpr
#else
@nlguillemot
nlguillemot / hashstr.cpp
Created July 20, 2012 06:55
comparison of constexpr hashed string with assembly
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{
@nlguillemot
nlguillemot / hashstr.cpp
Created July 20, 2012 07:22
compile time string hashing and assembly comparison
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{
@nlguillemot
nlguillemot / BAD EXAMPLE NUMBER 2 hashstr.cpp
Created July 20, 2012 07:39
constexpr string hashing compiler behaviour
#include <iostream>
constexpr unsigned _hash_string_recursive(unsigned hash, const char* str)
{
return ( !*str ? hash :
_hash_string_recursive(((hash << 5) + hash) + *str, str + 1));
}
constexpr unsigned hash_string(const char* str)
{