Friday, May 21, 2010
Blog moved
This blog has moved to http://vh4x0r.wordpress.com
Tuesday, May 4, 2010
Dell Inspiron 1464
Well, I bought a new Dell Inspiron 1464, and my old HP Pavilion is out for sale. It came with Windows 7 Home Basic, which I won't use, so I declined the EULA at the first bootup, and have applied to Dell for a Windows refund. I'm currently busy experimenting , and am bootstrapping gentoo on it ! Will report back on my progress ^_^
Thursday, February 25, 2010
Back to blogging
I haven't blogged in a while, mostly school stuff and exams ...
Well, I just bought 2 books on Perl from flipkart, they just arrived today ! One's the O'reilly "Llama book" and the other's "Perl Hacks", so I'm busy reading them. Looking forward to doing some real late night perl hacking ... ;-)
Well, I just bought 2 books on Perl from flipkart, they just arrived today ! One's the O'reilly "Llama book" and the other's "Perl Hacks", so I'm busy reading them. Looking forward to doing some real late night perl hacking ... ;-)
Friday, September 25, 2009
Fast nth fibonacci term generator
Here's some code to generate nth fibonacci term with some optimized recursion. Already generated terms are not regenerated. An array acts as a cache for the terms. Besides, integers are represented with char * allowing huge term calculations.
fibogen.c
~/devel/fibogen :) gcc -O3 -march=native -mtune=native -pipe -fomit-frame-pointer -ffast-math -o fibogen fibogen.c
fibogen.c: In function 'main':
fibogen.c:23: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result
~/devel/fibogen :) fibogen
Enter term to calculate: 5023
fibogen(5023) = 248560419649283678513006888062737004960134760988418307905373388505942986481060775195244084194714556882854137612073536664237785579120282065911785293337513886015023953145486883305558080183807994149392421109008029126965116981886956731180641266870009523965481202176011120065634469413284383112960712441923153798256342167123227820469383663417964899013751648010246443960641434024852096101024638451971960625796144677722737304551414781031490411571580459982050355471494276920439983581193010326994482515332997366158457073763985574602205889946564359072664645673996548528062294288463152531141939436109347821144918253984914858266331041933193284095453325649088264822747102089656780678368753206478819515483528828479426315024856137069121990789427595837059650018342996344614879040425051671211007345988321930553661789981247352356512907804456540716374221778890018510373603590988025872815600298159173656785237948221052073363317357008281570513166462291327747202547805549308377844086138173022395933493065635120665887076447216650309115602750732968703082884641717211142536157
Real Time: 0.22, User Time: 0.22, System Time: 0.00
Saturday, June 6, 2009
Fun with gcc
Had some fun with gcc today! I once wrote a program that reads words from a file, creates a linked list of the words, and then sorts them alphabetically! For a large text file, the memory overhead is pretty large. So, I used this to benchmark some gcc optimization flags, using all available parameters for the -march= flag!
And the results:
Also, a screenshot from KSysGuard, with the benchmark running!
Yet another reason why we should ditch binary based distributions for source based distributions! Gentoo rocks!
vikraman@charon ~/scripts/gcc-benchmark $ cat cpu-type-32I needed a hufe text file, so I took some issues of phrack, and ended up with a text file containing 1783 words. So, the bash script was:
native
i386
i486
i586
pentium-mmx
pentiumpro
i686
pentium2
pentium3
pentium-m
pentium4
prescott
nocona
core2
k6
k6-2
athlon
athlon-4
k8
k8-sse3
amdfam10
winchip-c6
winchip2
c3
c3-2
geode
vikraman@charon ~/scripts/gcc-benchmark $ cat benchmark.sh
#!/bin/bash
for cpu in `cat cpu-type-64`
do
echo $cpu >>benchmark.out
echo "">>benchmark.out
printf "\a"
gcc -march=$cpu -m64 -O3 -pipe -o sortwords sortwords.c
sleep 3
printf "\a"
/usr/bin/time -ao benchmark.out ./sortwords text >/dev/null
printf "\a"
sleep 10
echo "">>benchmark.out
done
vikraman@charon ~/scripts/gcc-benchmark $ cat benchmark.outClearly, -march=pentiumpro wins.
native
294.93user 1.30system 4:56.81elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
1712inputs+0outputs (9major+389047minor)pagefaults 0swaps
i386
295.30user 1.34system 4:57.03elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
i486
294.86user 1.34system 4:57.13elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
i586
295.21user 1.33system 4:57.42elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
pentium-mmx
295.13user 1.37system 4:58.77elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
pentiumpro
294.33user 1.28system 4:56.29elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
i686
295.29user 1.56system 5:01.18elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
pentium2
294.67user 1.23system 4:58.56elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
pentium3
297.29user 1.36system 5:00.79elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
pentium-m
294.18user 1.29system 4:58.19elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
pentium4
294.99user 1.49system 4:58.48elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
prescott
294.87user 1.56system 4:58.06elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
nocona
295.71user 1.45system 4:59.41elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
core2
295.35user 1.46system 4:59.52elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
k6
295.04user 1.44system 4:57.40elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
k6-2
295.45user 1.48system 4:58.42elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
athlon
294.66user 1.37system 4:58.69elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
athlon-4
295.32user 1.49system 4:58.14elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
k8
295.48user 1.46system 4:59.84elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
k8-sse3
295.42user 1.52system 4:58.32elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
amdfam10
295.34user 1.49system 4:57.75elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
winchip-c6
298.74user 1.60system 5:02.45elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
winchip2
296.82user 1.29system 4:58.51elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389055minor)pagefaults 0swaps
c3
294.99user 1.39system 4:58.81elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
c3-2
294.38user 1.32system 4:56.74elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389057minor)pagefaults 0swaps
geode
294.53user 1.43system 4:58.47elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+389056minor)pagefaults 0swaps
Also, a screenshot from KSysGuard, with the benchmark running!
Yet another reason why we should ditch binary based distributions for source based distributions! Gentoo rocks!
Running KDE 3.5 without arts
I compiled KDE on my gentoo install with -arts USE flag. So I needed an alternative for playing the KDE sound notifications. So I wrote a program in C to launch the appropriate player for each type of audio file, in a forked process.
References: http://www.gentoo-wiki.info/TIP_Audio_notifications_in_KDE_3_without_aRts
(Actually there is a mistake in the program on the gentoo wiki which I corrected)
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc != 2) {
printf("Exactly one argument expected.\n");
return 0;
}
char *ext = strrchr(argv[1], '.');
ext++;
if (ext == NULL) {
return 1;
}
if (fork() == 0) {
if (strcmp(ext, "wav") == 0)
execl("/usr/bin/aplay", "/usr/bin/aplay", "-q", argv[1], NULL);
else if (strcmp(ext, "ogg") == 0)
execl("/usr/bin/ogg123", "/usr/bin/ogg123", "-q", argv[1], NULL);
else if (strcmp(ext, "mp3") == 0)
execl("/usr/bin/mpg123", "/usr/bin/mpg123", "-q", argv[1], NULL);
else
execl("/usr/bin/mplayer", "/usr/bin/mplayer", "-vo", "null", "-really-quiet", argv[1], NULL);
}
return 0;
}
References: http://www.gentoo-wiki.info/TIP_Audio_notifications_in_KDE_3_without_aRts
(Actually there is a mistake in the program on the gentoo wiki which I corrected)
Subscribe to:
Posts (Atom)