Saturday, January 14, 2012

Software Tuning for fun

If you asked me 15 years ago what my primary programming language was, I would have answered “c”. But it is very hard to produce a gui app in c, and shortly there after I started using Delphi. Delphi with a add on MySQL Database Library called MySQLDAC makes a powerful environement allowing the quick development of useful database applications.

As I became more and more interested in Linux (I have always liked obscure OS's since I used to use OS/2), I became aware of a Delphi for Linux (and other OS's) called Lazarus.

In reality it is two products in one, the front end app is indeed called Lazarus and is a GUI Application Development Environment very similar to Delphi, but behind it sits Free Pascal. Free Pascal is a Object Pascal compiler that is almost identical to the Object Pascal that Borland came up with all those years ago. So in effect you write your app in Lazarus and then Lazarus hands it over to Free Pascal to acually compile it.

So if you want to write a GUI App, you can use Lazarus and if you want to create a non GUI App, such as something you can use in a Cron App (Cron runs tasks in the background in Unix enviroments), it can be written in straight Pascal. It is easier to write then c and everything seems wonderful in the world.

Now my primary Desktop is a HP with a AMD 64 bit Quad Processor. More specifically it is a Phenom 9150e. And at the time I had a Dual Core Pentium (32 bit) cpu which I used for traveling and when I am otherwise away from home. I found a copy of the Dhrystone benchmark written in Pascal and on a lark ran it on the laptop and then later for comparison purposes on the desktop. The laptop blew the desktop away. How was this possible, the desktop had a 64 bit cpu while the laptop was running an older 32 bit cpu.

Well, AMD Processors have their own instruction sets that is similar to the intel instruction set but NOT the same. If an AMD processor sees an Intel instruction it runs it in a interpeted mode, which gives correct results but runs much slower. Well the Free Pascal Compiler seems to generate only Intel instructions and there is very little tuning that can be done. There were a couple of recommendations given on the Lazarus Forum, but it made virtually no difference.

I then found the Dhrystone Benchmark written I c, compiled and ran it on both machines and the run times were much as I would have expected, with it running much faster on the desktop.

In truth with the speed of modern computers you really aren't going to notice the slowdown that much unless you throw a lot of data at it. The moral of this part of the story is if want to run Free Pascal and want it to run fast, get an Intel Processor. To be fair to Lazarus and Free Pascal, they are a very small project that is only supported by hobbyists alone.

A few weeks ago I decided to have a little refresher course in c, so I wrote some programs that created some large MySQL tables and then did some crunching with them. MySQL was actually doing most of the work, but the c programs were issuing the queries to be ran. Well you can tune c programs written using the gcc compiler a lot better then Free Pascal. But gcc, is supported by large corporations (like IBM and HP) and has a lot more money to work with.

On the desktop I tried compiling it three different ways:

  1. No tuning: gcc Program.c -o Program `mysql_config --cflags –libs`

  2. Using mtune switch: gcc -mtune=athlon64 Program.c -o Program `mysql_config --cflags –libs`

  3. Using the march switch: gcc -march=native Program.c -o Program `mysql_config --cflags –libs`


I ran the programs multiple timmes giving me a average runtime:



No Tuning

mtune=athlon64

march=native

Wall Time

6.2 seconds

6.19 seconds

6.22 seconds

User App time

0.75 seconds

0.75 seconds

0.77 seconds






The gcc web site recommends using “-march=native” which in this case gave the worst performance, but not by much. I did just as well by not tuning at all!!! For the record, wall time is the actual runtime as seen on a clock. I got these results by running the script using the Unix time command.

But, I have since upgraded my laptop to a Intel i5 cpu and the results are a little different.



No Tuning

mtune=native

march=native

Wall Time

5.68 seconds

4.78 seconds

4.62 seconds

User App time

1.08 seconds

0.75 seconds

0.74 seconds






So in this case, tuning seems to have helped. In both of these tables most of the wall times appears to be spent waiting on the MySQL Server to finish running the queries.

Friday, December 16, 2011

Haimann

HAIMANN is a very rare last name

Very few last names in the US are HAIMANN

Be proud of your unique last name!

source: namestatistics.com

Monday, July 11, 2011

Chess Beginners avoid the QGA

Really, beginners shouldn't play Queens Gambit Accepted.

1. d4 d5
2. c4


The c4 pawn looks free, but it really isn't. Once black gets the pawn it is very hard to hold on to it. Usually white responds with a quick e4, which not only puts a discovered attack on the black pawn (from the light squared Bishop) but also gets control of the Center. White has more then gotten compensation for that pawn. I'm not saying QGA isn't playable from blacks side. It is, but it usually takes a somewhat seasoned player.

I can and have had a lot of fun when a unseasoned player takes my pawn. The games I get like this can be a lot of fun for me, but they must be a little humiliating from blacks perspective.

I played a recent game on FICS where my opponent accepted the gambit.

1. d4 d5
2. c4 dc (short hand for d5 x c4)
3. e4 e5


Black would really love white to de (d4 x e5). Then black could exchange Queens and after white takes back with his King (he has no choice at that point,) white can no longer castle. After that black looks forward to at least an equal game, if not better.

4. Nf3 Bb4+
5. Nbd2 (That is Knight on b to d2)
Bxd2
6. Qxd2
Studies indicate that unless there is additional compensation a Bishop for a Knight is a bad exchange. A mathematical analysis says that Knights are worth 3 points, but a Bishop is really worth 3.5.
6. ed
7. Bxc4 Nf6



8. e5 Ne4
9. Qxd4 Qxd4
10. Nxd4 o-o
11. o-o c5
12. Nf3 Nd7
13. Re1



Well now, black is now down a whole pawn and where does that Knight think he is going. In truth did I plan this, uh, no. This was speed chess (time control was 2 minutes to start and 12 seconds added to your clock for each move you make) and all I was doing was making natural moves and not thinking about it very hard. And now black was going to be a whole minor piece down. I refuse to play slow chess on FICS, there is too much cheating.

13. Nxf2
14. Kxf2 Re8
15. e6 fe
16. Bxe6+ Kf8
17. Bf7





I realized right after making this move, that I had created a Check-Mate threat (Bd6.) Blacks best move here is g6, but even with best play black will be on the defensive for the rest of the game.

17. Nf6
18. Bd6+

Black now has to block the Bishop with the only piece available, the Rook. If I had his position, I would resign. All I have to do now is get light squared Bishop out of the way and I will win the Rook outright.

18. Re7
19. Bxc8 Bxd7
20. Bxe7+ Kxe7
21. Bxf6

There was no point in not trading down, my opponent was down a Rook and a Knight. The game went on for a few more moves but after I went after his pawns he gave up.

The most important point here is that control of the center is worth more then a pawn. Don't take that pawn unless you can create tactical complications elsewhere. I recommend looking at something like the Tarrasch or the Slav Openings instead. Some older games of mine that further demonstrate this point are here.

I have a copy of ChessBase which is a few years old. I ran a report on this opening and this is statistics for strong players using these lines:

Black Scores below average (42%).
Black performs Elo 2239 against an opposition of Elo 2295 (-56%).
White performs Elo 2338 against an opposition of Elo 2282 (+56%).
White wins: 9640 (=41%), Draws: 8034(+34%), Black wins: 5913 (+25%).
The drawing quote is Average. (9% quick draws, < 20 moves).

White wins are shorter then average (37).
Black wins are of average (40).
Draws are shorter than average(32).

So, even Masters don't do that well as black with this line.




Wednesday, January 21, 2009

Northern Flicker

I accepted another position from my employer last June. The hours are better and I can pretty much set my own schedule, but the work site is on the other side of town and the walking situation isn't nearly as good. I have two choices now as to where to walk.

Brown's Woods, is a dense wooded area on the border between Des Moines and West Des Moines. There is a lot of wildlife there, but due to denseness of the woods the wildlife can be hard to see. You hear a lot of animals, but see very little. The trails there are also fairly primitive and they make no attempt to clear them. So, after we got a thick layer of ice there last December, I gave up. I might giver it another try in February after a good thaw.

My other choice is the Great Western Trail which runs through Des Moines. The area that I walk there is just south of the Des Moines Water Works which goes through the Des Moines Water Works. I normally turn around in the Water Works. I see a lot of geese during the summer and an occasional Blue Heron. Rose Breasted Grosbeaks are also common, but it is harder to get an image of them there. It is actully more road then trail, but I take what I can get This time of year I rarely see any wildlife.

Today I got lucky though and saw a Northern Flicker, it is the Yellow Shafted variant. It was so busy eating some berries, I was able to get about a half dozen images of which the following was the best.



Thursday, January 08, 2009

More Chess

1. d4 (0:00) d5 (0:00)

He opened with d4 and I am going to go into the Tarrasch.

2. e3 (0:02) e6 (0:01)
3. Bd3 (0:03) c5 (0:01)
4. c3 (0:02) Nc6 (0:04)
5. Nd2 (0:04) Nf6 (0:03)
6. f4 (0:03)



Thats is risky. The e3 pawn will become weak later in the game, Right now I can't get at it. He is probably planning an all out attack against my King side.

6. ... Be7 (0:06)
7. Ngf3 (0:01) O-O (0:04)
8. Ne5 (0:03) Qc7 (0:05)
9. O-O (0:06) c4 (0:24)
10. Bc2 (0:11) b5 (0:03)
11. Rf3 (0:07) b4 (0:03)
12. Rh3 (0:18) h6 (0:13)



His Rook will neeed assistance, right now my knight is preventing his Queen from coming in.

13. Qf3 (0:18) Rb8 (0:07)
14. Ba4 (0:41) Bb7 (0:13)
15. g4 (0:20) Nd7 (0:15)
16. Nxc6 (0:37) Bxc6 (0:03)
17. Bc2 (0:11) f6 (0:03)
18. Qg3 (0:16) e5 (0:15)



My position was getting cramped, I am pushing pawns to give myself a little more mobility.
19. fxe5 (0:20) fxe5 (0:03)
20. dxe5 (0:51) Nxe5 (0:03)
21. Nf3 (0:22) Bd6 (0:05)
22. Nxe5 (0:22) Bxe5 (0:03)


Ok. I have opened up the f file giving my rook full mobility. He hasn't fought me for it. Now he is becoming cramped.

23. Qe1 (0:14) Rbe8 (0:14)
24. Bd2 (0:22) d4 (0:02)


I am trying to set a little trap here. If e3 takes d4, Bishop then takes h2 check with a discovered attack on the Queen. But he sees it and moves the Queen out of the way. Which allows me to trade pawns and force his Bishop back to e1 or c1.

25. Qd1 (0:32) dxc3 (0:08)
26. bxc3 (0:09) bxc3 (0:04)
27. Be1 (0:12) Qf7 (0:49)


Queen to f7 threatens mate.

28. Bh4 (0:53) Rd8 (0:23)

If his Bishop takes my rook, Queen f2 is check mate.

29. Qe2 (0:09) Rd2 (0:09)



Rook to d2 was a very strong move. I can win the Queen now and there is very little he can do about it.
If he steps out of the way, I can mate him.


30. Qe1 (0:39) Rg2+ (0:05)

He offered me a draw at this point. It is mate next move. My response: Nyet! He then resigned

King to h1 is forced, then Rook to g3 is check Mate (discovered check mate with the Bishop.) Why win a Queen when you can win the King.

Wednesday, January 07, 2009

A Quickie

White out ranks me by about 100 points, but my rating has been in the dumps.
Mostly because I will play when I am to tired.

1. Nf3 (0:00) d5 (0:00)
2. b3 (0:02) c5 (0:03)
3. e4 (0:01) d4 (0:03)
4. Bc4 (0:10) Nc6 (0:03)
5. a3 (0:09) e5 (0:02)


This is probably a line, but I don't know it. It looks strange to me.
I am just trying to play sound center developing moves.

6. Qe2 (0:11) Be7 (0:13)
7. O-O (0:10) Nf6 (0:03)
8. Ng5 (0:04) O-O (0:04)

Go ahead and trade two pieces for a rook!

9. f4 (0:01) exf4 (0:06)

Probably a mistake on my part. Should have made him take and I retake with
a well placed night.

10. Rxf4 (0:03) Ne5 (0:03)
11. Rxf6 (0:31)


Wow, that has to be unsound!

11. ... Bxf6 (0:06)
12. Nxf7 (0:28)

Throwing good money after bad. Or, in for a penny, in for a pound.

12. ... Nxf7 (0:06)
13. d3 (0:06)

Pushing e5 would be better. But even so, I can give back some of
my profit.

13. ... Kh8 (0:08)

I have broke the pin.
14. Qh5 (0:06) Ne5 (0:14)

He puts a double hit on my knight and I just move it out.

15. Bd5 (0:07)

At this point I realize his Queen is looking awfully helpless.

15. Bg4 (0:17)


And White resigns, because his Queen is trapped.

Tuesday, January 06, 2009

Ice Jam

For the last few months I have been walking in Browns Woods, West Des Moines IA. for my lunch break. Well about two weeks ago the top layer of snow melted off leaving a thick layer of ice on the trail. I decided not to try walking on that since the risks exceeded the benifits. So, I tryed going back to Great Western Trail, which leads into Des Moines Water Works Park. When I went down there though, I saw the access was closed. The sign said water over the road.

We had had a couple of really warm days which allowed the Raccoon River to partially melt causing a ice jam to occur. So for the last couple of weeks I haven't been able to walk on my lunch break (bummer!) Well yesterday they opened the trail access to the Great Western Trail back up and I went down to look, unfortunatly I forgot my camera. Well today I brought it.



This was my first image overlooking the Raccoon River. According to my best estimate, the river is between 75 - 100 yards wide.



These are the blocks of ice strewn along the road. I assume the City had to use heavy equipment to clear the road of these blocks of ice.

That is my shoe up against a block of ice to show how thick they are. My shoe measures 12.5 inches long.

More images just showing how much ice is really here.




Images using a nearby car to show the physical size of it all.

The following two images showing broken trees in the river.


I really liked the broken tree trunk pointing straight up.

And finally a shot taken from a bridge crossing the river.

Friday, April 11, 2008

Checkmate with a Pawn!!!

1. d4 (0:00)

Ok, agianst d4 I usually play the Tarrasch.

d5 (0:00)


2. e3 (0:01) e6 (0:01)
3. Bd3 (0:01) c5 (0:02)
4. c3 (0:01) c4 (0:02)
5. Bc2 (0:01) Nc6 (0:04)
6. a3 (0:01)

Nf6 (0:03)
7. f4 (0:02)

f4 just leaves an ugly pawn formation.

Be7 (0:03)
8. Nf3 (0:01) O-O (0:03)
9. O-O (0:01) Nd7 (0:24)

Clearing the way to push pawns and destroy his center.


10. Qe2 (0:01) f6 (0:02)

11. Nbd2 (0:01) e5 (0:05)
12. fxe5 (0:14) fxe5 (0:02)
13. e4 (0:03) dxe4 (0:05)
14. Qxe4 (0:05) Nf6 (0:11)
15. Qe2 (0:15) exd4 (0:04)
16. Qxc4+ (0:05)

Oops, forgot about that.

17. Nxd4 (0:01) Nxd4 (0:11)
18. cxd4 (0:02) Qd5 (0:39)

I am not so bad, He's a pawn up but it is an isolani
and my pieces are better developed.

19. Qxd5 (0:06) Nxd5 (0:02)
20. Nb3 (0:01) Bd7 (0:20)
21. Bd2 (0:02) b6 (0:08)
22. Bd3 (0:13) Bd6 (0:13)
23. Rxf8+ (0:04) Rxf8 (0:03)
24. Rf1 (0:03) Be6 (0:11)
25. Rxf8+ (0:03) Bxf8 (0:03)
26. Bc4 (0:13) Be7 (0:18)
27. Bxd5 (0:02)

He's trading a good B for a N, He will pay
for that

Bxd5 (0:03)
28. Nc1 (0:08) Bf6 (0:04)
29. Bc3 (0:01) a5 (0:21)
30. Nd3 (0:03) b5 (0:04)
31. Nf4 (0:07) b4 (0:13)
32. axb4 (0:02) axb4 (0:05)
33. Bxb4 (0:04)

Well there goes his Isolani and it creates another,
ok technically its a passed pawn.

Bxd4+ (0:02)
34. Kh1 (0:01) Bf7 (0:08)
35. Bc3 (0:02) Bb6 (0:04)

Notice how much area my bishops are covering.

36. Nd3 (0:03) Bc4 (0:03)
37. Nb4 (0:04) h5 (0:05)
38. Nc2 (0:09) Kh7 (0:04)
39. Ne1 (0:02) g5 (0:03)
40. Nf3 (0:01) g4 (0:11)
41. Ne5 (0:05) Bb3 (0:05)
42. Nd7 (0:05) Bf2 (0:09)
43. Nf6+ (0:05) Kg6 (0:03)
44. Ne4 (0:08) Be3 (0:05)
45. Ng3 (0:09) h4 (0:21)

Notice that by moving his knight around attacking willy-nilly,
I am advancing my pawns.



46. Ne2 (0:03) Kf5 (0:16)
47. g3 (0:01) h3 (0:13)

I totally missed that Be5 is check mate!

48. Nf4 (0:08)

Unfortunately now I see it, but now to get it I am going to
have to maneuver.

Ba4 (0:12)
49. Ng2 (0:51)

He wants me to take his knight with my pawn, which would
allow his K to get out of that corner.

Bc6 (0:06)

This pins the knight allowing me to take it at my leisure
50. Bd2 (0:15) hxg2# (0:10)

Checkmate with a pawn!!!

Mostly March & Early April

2008.03.06

15.01 Temperature 30 degrees and clear, walking on the Pioneer Walkway.
15.04 Creek is free of ice. It is very brown and dirty looking.
15.15 Image taken of a large chunk of ice in the river.

2008.03.09

13.49 Seeing geese in creek a hundred yards off or so.
13.52 Now that I am closer I can see about 20 geese, have taken an image.


13.58 Have gotten some images of ducks on the creek also.


2008.03.10

14.12 35 degrees and sunny. I am walking on the Des Moines River trail.
14.25 Only seen squirrels.
14.36 Image attempted of eagle overhead in flight (sorry its a little blurry, but it is the best
one like this I've gotten.)


2008.03.13

13.30 Walking on the Pioneer trail. Partly clear, 58 degrees.
13.32 First robin of the year seen, no image taken.
13.33 Eagle seen in flight, image attempted, but unsuccessful.
13.35 Image taken of a robin bathing in a crick.


13.39 Image taken of a sparrow sized bird. It is probably a warbler or some sort of fly catcher.

13.43 The ground surrounding the trail is very soggy, water standing in many places, but hasn't breached the trail. I suspect it is a near flooding situation.
13.45 Robins are all over the place now. They must have arrived in force in the last few days.
13.47 Image of what I suspect is a nuthatch. (Sorry the Nut-Hatch is slightly out of focus.)
14.01 Large chunks of ice on the other bank seen, images taken.


14.18 Image taken of a smallish woodpecker.

2008.03.14

13.41 Mid fifties today with a light breeze.
13.59 Seeing lots of robins and not much else.
14.01 Image of Hairy Woodpecker. After inspecting the images, the bottom one has two
woodpeckers in it.


2008.03.15

13.43 Cloudy in the mid 30's. Its drying out a little, but rain is forecast over the next few days.
13.54 Image taken of what are probably Hairy Woodpeckers.
15.58 The trail near the creek, is mostly passable. Yesterday I had to inch my way on the ice bridge
on the edge of the trail but now it is mostly clear. The ice bridge was created when they plowed and then
the snow pack turned to ice.
14.00 Got an image of a male duck. I don't see the female though, but she has to be near by. Inspection of
the images revealed that the female was there, her camouflage was elegant. Look for orange, left of center and you will find a duck attached to it.


14.17 Tried to get an image of a small woodpecker, but I don't think I got it.
14.22 Tried to get an image of a pair of Rose Breasted Grosbeak.

2008.03.18

15.00 Walking on the River Trail I had a mink sighting and got several images of a cardinal.


2008.03.20

13.45 Walking on the Pioneer trail. Its clear and about 55 degrees.
14.02 Several images of a Rose Breasted Grosbeak.
14.07 I see the ducks that I last saw on the creek in a flooded area just to the east of the trail. Image not possible.
14.25 Several images taken of a ducks in the creek. I think they are Mallards.


2008.03.21

13.40 Its mostly clear today and about 45 degrees with a brisk wind of about 25 mph.
13.42 Image taken of a small sparrow sized bird (They turned out to be Goldfinches and blurry.)
Goldfinches are the State Bird of Iowa.
13.49 Image taken of what may be a meadowlark. (I believe they were Meadowlarks, but the images were poor.)
14.04 Image taken of a sparrow sized bird. I think it is a American Tree Sparrow.

14.09 More images of a sparrow sized bird. Why because I could. I am not sure what it is.


14.19 Saw a Rose Breasted Grosbeak, but unable to get image.
14.28 Saw a pair of eagles roosting on downed log, but they flew off before I could get the camera booted up.

2008.03.25

13.42 Its clear and about 55, but windy.
13.54 Image taken of a possible field hawk. Probable Red Tailed Hawk.



13.59 Eagle spotted in flight, no image attempted.
14.27 Images attempted of small sparrow sized birds, they are very very active.
I have not identified it.


2008.03.26

13.37 Several images taken of what may be a meadowlark.
13.56 Image taken of a cardinal.


14.00 Several images taken of goose on a sandbar in the creek.
14.09 Noticing trees are starting to bud out. Image taken of a tree bud.


14.00 Several images taken of goose on a sandbar in the creek.
14.09 Noticing trees are starting to bud out. Image taken of a tree bud.

2008.04.01

13.42 Upper 40's today and mostly cloudy.
14.08 Several images attempted of a probable Hairy Woodpecker.
14.10 Image taken of unidentified bird.
14.14 Image taken of a Rose Breasted Grosbeak.
14.40 Several images of some sort of hawk, estimated distance 100 meters.

2008.04.02

13.25 Sunny upper 50's.
13.44 Took an image of a robin, because I haven't seen anything else.
13.50 Several images of a deer taken.


13.58 Several images of an unidentified bird.
14.11 Blue jays spotted, but image unsuccessful.
14.14 Hairy Woodpecker image taken.
14.16 Images taken of deer.
14.27 Images attempted of what appears to be a hawk.

2008.04.07

13.35 Image taken of an unidentified bird.
13.45 Peepers(frogs) are loud, but I can't see any.
13.51 Image taken of a peeper(frog.)


13.56 Image taken of unidentified bird.
14.09 Images taken of geese in the creek.



2008.04.09

Walked, but forgot my voice recorder. Didn't walk on the 8th due to heavy rain.

The following image was taken on the 9th. I don't know for sure what it is, but I suspect some sort of fly catcher or a Warbler. And lastly I got another picture of a Peeper.