Archive

Archive for the ‘funstuff’ Category

benchmarking std::vector

January 12th, 2010 No comments

so i always wondered whats the fastest way is to iterate over a vector. So with this little snippet you can find out for yourself:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// some simple std::vector benchmark tool
// Jan 2010, thomas{AT}thomasfischer{DOT}biz
// also see http://stackoverflow.com/questions/776624/whats-faster-iterating-an-stl-vector-with-vectoriterator-or-with-at
#include <stdio.h>
#include <vector>
#include "Timer.h"

#define VECSIZE 500000


typedef struct foo_t {
    char tmp[2];
} foo_t;

int main(int argc, char **argv)
{
    int amount = VECSIZE;
    int tests = 10;
    printf("testing with %d elements a %d bytes (%0.2f MB) and %d runs per test\n", amount, sizeof(foo_t), (amount*sizeof(foo_t))/1024.0f/1024.0f, tests);
   
    double time = 0.0f;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        vec.reserve(amount);
        foo_t f; // with random data in it
        Timer *t = new Timer();
        for(int i=0;i<amount;i++)
            vec.push_back(f);
        time += t->elapsed();
    }
    printf("add time (resized before): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        foo_t f; // with random data in it
        Timer *t = new Timer();
        for(int i=0;i<amount;i++)
            vec.push_back(f);
        time += t->elapsed();
    }
    printf("add time (dynamic resize): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        foo_t f; // with random data in it
        for(int i=0;i<amount;i++)
            vec.push_back(f);

        Timer *t = new Timer();
        for(std::vector<foo_t>::iterator it=vec.begin(); it!=vec.end(); it++)
        {
            // some example usage
            it->tmp[1] = 0;
        }
        time += t->elapsed();
    }
    printf("iterate time (version #1): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        foo_t f; // with random data in it
        for(int i=0;i<amount;i++)
            vec.push_back(f);

        Timer *t = new Timer();
        std::vector<foo_t>::iterator vecEnd = vec.end();
        for(std::vector<foo_t>::iterator it=vec.begin(); it!=vecEnd; ++it)
        {
            // some example usage
            it->tmp[1] = 0;
        }
        time += t->elapsed();
    }
    printf("iterate time (version #2): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        foo_t f; // with random data in it
        for(int i=0;i<amount;i++)
            vec.push_back(f);

        Timer *t = new Timer();
        for(int i=0; i<amount; i++)
        {
            // some example usage
            vec[i].tmp[1] = 0;
        }
        time += t->elapsed();
    }
    printf("iterate time (version #3): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        std::vector<foo_t> vec;
        foo_t f; // with random data in it
        for(int i=0;i<amount;i++)
            vec.push_back(f);

        Timer *t = new Timer();
        for(unsigned int i=0; i<vec.size(); ++i)
        {
            // some example usage
            vec.at(i).tmp[1] = 0;
        }
        time += t->elapsed();
    }
    printf("iterate time (version #4): %f\n", time/tests);


    time=0;
    for(int i=0;i<tests;i++)
    {
        foo_t vec[VECSIZE];
       
        Timer *t = new Timer();
        for(int i=0; i<amount; ++i)
        {
            // some example usage
            vec[i].tmp[1] = 0;
        }
        time += t->elapsed();
    }
    printf("iterate over array (version #1): %f\n", time/tests);

    time=0;
    for(int i=0;i<tests;i++)
    {
        foo_t *vec = (foo_t *)malloc(sizeof(foo_t) * amount);
       
        Timer *t = new Timer();
        for(int i=0; i<amount; ++i)
        {
            // some example usage
            vec[i].tmp[1] = 0;
        }
        time += t->elapsed();
        free(vec);
    }
    printf("iterate over array (version #2): %f\n", time/tests);

    return 0;
}

to compile, add the Timer.h from my previous post :)

which results in the following output on my windows machine (/Oi /O2)

testing with 500000 elements a 2 bytes (0.95 MB) and 10 runs per test
add time (resized before):       0.005281
add time (dynamic resize):       0.007693
iterate time (version #1):       0.004180
iterate time (version #2):       0.004107
iterate time (version #3):       0.000903
iterate time (version #4):       0.004891
iterate over array (version #1): 0.000277
iterate over array (version #2): 0.000773

what are your results?

Categories: coding, cpp, funstuff Tags:

new founded projects : overview

August 6th, 2009 No comments

small update on some side projects i started over the last months:

(all of those are currently actively used by me, so if you get problems, let me know)

Categories: coding, funstuff, python, website Tags:

munin alternative

May 28th, 2009 No comments

just started a new project called 'monitordatasink' (im kind of uncreative in such naming things...).
Jut hop over to http://code.google.com/p/monitordatasink/ and have a look yourself. happy monitoring! :)

Categories: coding, funstuff, hardware, python, server, website Tags:

how to get the client IP in python XMLRPC – the easy way

May 26th, 2009 No comments

some time i wrote a post of how to do it the complicated way, so today the easy way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import SimpleXMLRPCServer
import os.path
import rrd

monitor = None

class Monitor:
    def getMyIP(self):
        return "your IP is: %s" % monitor.clientIP

class myHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
    def do_POST(self):
        global monitor
        monitor.clientIP, monitor.clientPort = self.client_address
        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.do_POST(self)

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("",8888), myHandler)
monitor = Monitor()
server.register_instance(monitor)
server.serve_forever()
Categories: coding, funstuff, python Tags:

capture video of 3d applications under linux

May 5th, 2007 No comments

There is a nice project called "yukon" http://www.neopsis.com/projects/yukon/
This program is nice to capture i.e. blender or game programs which are using openGL.

So here it is how to get it working:
1. follow this to install: http://www.neopsis.com/projects/yukon/wiki/HowTo/Install
2. create some scripts:
startyukon.sh:

#!/bin/sh
YUKON_OUTPUT="file://`pwd`/$1.seom" YUKON_FPS=30 YUKON_VERBOSE=1 YUKON_SCALE=0 yukon $1

and

convertseom.sh:

#!/bin/sh
seom-filter $1 | mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=3000 -o $1.avi -

this example config is ignoring sound, if you want sound, you must change this config.

3. run like this:

./startyukon blender

4. Press F8 inside Blender and do something (i.e. create a mesh or so). press F8 again and exit blender normally.

5. convert the output .seom file like this:

./convertseom.sh blender.seom

6. view result:

mplayer blender.seom.avi

happy recording :-)

Categories: 3dstuff, coding, funstuff, gentoo Tags:

installing OGRE, ode and everything else

April 12th, 2007 No comments

just updated my little guide over here, so if anybody has problems, feedback welcome :-)

Categories: 3dstuff, coding, funstuff, gentoo Tags:

3d screenshots

April 3rd, 2007 No comments

create 3d-screenshots of every DX9 application as easy as 2d screenshots, believe it or not:
http://www.deep-shadows.com/hax/3DRipperDX.htm
and it's free!

so i tried it with S.T.A.L.K.E.R. and imported the result into a trial of 3D Studio Max 7:

screen of imported scene:
stalker1.PNG

scene in close-up:

stalker2.PNG

same scene rendered:

stalker3.PNG

can you see the gun in the hand of the guard?
isolated, extracted and rendered:

stalker4.PNG

This works for nearly every game that uses directX9.
Another test with Rayman Raving Rabbits:

rrr.png

i think this is really, really cool :-)

(note this is done for educational purposes only)

Categories: 3dstuff, funstuff Tags:

most senseless portage

March 11th, 2007 No comments

emerge cowsay

try youself, and give me just one possible usage: # cowsay -f elephant.cow foobar!

Categories: funstuff, gentoo Tags:

human computation

March 10th, 2007 No comments

just found a really interesting google talk about captchas:watch yourself

i think this was the starting point for Google Image Labeler :-)

Categories: funstuff Tags:

best error ever

March 10th, 2007 No comments


as i was just about to throw gentoo in the bucket, and installing debian

Categories: funstuff Tags: