Daily stuff not frequently posted a software developer finds out or rants about.

Monday, August 24, 2009

Performance tests

From time to time, I wonder which drain "nice" codewriting has on performance.



The Pred(n) vs. n-1 thing:



The classic thing seems to be running loops to n-1, but somehow I grew to appreciate the look of Pred(n) in loop end parameters - as a prefix, its easier to see on wide lines and small screens, for instance.



This needs one billion runs to at least show a difference that could be recognized and is not influenced by the minimum time span of the standard Windows API (you can go more exact if you want, but I did just raise the number of runs). With such a test set that is large enough, the time needed is exactly the same.



My conclusion: keep it as it is - using more Pred(n) as I write now or update old code, but without hurries to port old code over for performance reasons.

The FreeAndNil(o) vs. o.Free thing:



Coding with .Free means there is no dependency to the huge unit SysUtils, and is one call less, which is why I preferred it for quite a while, until I learned the advantages while debugging if destructed objects are set to nil (the Watch would otherwise case AVs, or disturb FastMM). So I went ahead and compared two loops of construction/destruction.



FreeAndNil(o) takes 5.703 seconds, o.Free takes 5.625 seconds. That's a difference of 0.078 seconds (for a 10 million operations loop), or about 1.4%.



While FreeAndNil is slightly smaller, ten million destructions are something that few applications will do, and even if they do, less than a tenth of a second can be spared to make memory leak testing much easier.

Tuesday, July 28, 2009

Universal Cosmonaut open-sourced

Two years ago, I published pk3DConnexion.pas, my unit for using the SpaceNavigator in Delphi, here. Recently, someone from the 3DConnexion forums asked my for the source, so I decided to open-source this small project that I have to admit I haven't updated in quite a while.

Launchpad: Universal Cosmonaut

May it help :)

Amazon queries updated

Amazon has recently updated their webservices to require signed requests in the near future, so it became time to address this in my snlProtoAmazonOnca.pas unit.

The basics: parameters need to be sorted (byte, not alpha order!), properly encoded (RFC 3986 2.2), and a signature based on a special string created and appended.

This means the secret key is now needed for requests as well. Additional dependencies had to be added: I chose a HMAC/SHA256 algorithm by W. Ehrhardt and Base64 encoding by Daniel Wischnewski.

An upload will take place once I've decided the two above are really fine (license- and quality-wise).

Wednesday, June 24, 2009

This blog's not dead: more open source

While clearing out some stuff I came across an old blue laser I still had stored away from a time we did play some small lasershows, and I remembered the software I wrote to create those shows - it was my first Windows project that took nearly a hundred hours of work. Searching the net or references to this, I found it still mentioned in 2009, about ten years afterwards and eight years after the last change I made to it.

Reading that people want more features, but me not having a lot of time, I decided to use that for another experiment: trying out an online version control system other than SourceForge. I somehow remembered Launchpad and decided to submit the code there:

Heathcliff for Catweazle LC1 - Yoghurt Mixer

If you wonder about the name: Catweazle LC1 is the unit we used to direct the laser beam, and from ads in that time, LC1 was something about purposed healthy counterclockwise turning or something yoghurt acids. The output is by soundcard (usually for debugging) or better CD-Player (through .wav output) - the left and right channels control the x- and y-axis of the LC1 (or other similar units).

Continuing to play with Launchpad, the other open source project you'll have encountered here would be Collection Templater, which has gone version-controlled as well. Though while the later is published under the LGPL, Heathcliff even is GPL'ed, since it odoes not have as many dependencies (actually, the only ones are Toolbar2000 and Toolbar97, which I intend to get rid of as well at some point)!

Launchpad uses the Bazaar version control system, which I like more than cvs or svn at this time.

Labels: , , , , , ,

Thursday, June 05, 2008

Amazon and Eraser APIs updated

This is just a small update, related to two of the files I made available here.

The Amazon lookup unit, snlProtoAmazonOnca.pas, has been updated since Amazon does no longer support the DevToken method. The quick fix in the unit just raises an exception when it is used to allow supporting code to still compile; replacing it with the AssociateID method is a must though for your app to be able to query again.

Also, the 5.8.6 Eraser update was too C-ish, no longer exporting plaintext function names in Eraser.dll. The updated snlAPIEraser.pas contains a quick fix for 5.8.6, with the hope that they'll get back to "proper" exporting with the next version.

The new file revisions are available through their links at the right side of this blog.

Labels: ,

Friday, November 23, 2007

Eraser API headers

Do you know Eraser? It's a tool that allows you to remove sensitive files in a really persistent way that should be unrecoverable, using mechanisms defined even by the U.S. Department of Defense, as well as security experts.

Eraser offers a library that allows other software to use it. This software in itself needs to be GPL'ed as well according to their source page, but this requirement is not mentioned during installation or on the download page itself. So the situation is a bit unclear. I've written a small Pascal file that defines the links to Eraser and implements a mini class to use, and am publishing it here now in case some GPL software wants to use it: snlAPIEraser.pas.

Usage should be easy:

   GEraser := TEraser.Create;
   if GEraser.IsAvailable then begin
      GEraser.EraserInit;
   end;
   // app code
   if GEraser.IsAvailable then begin
      Result := GEraser.EraserRemoveFile(Filename);
   end;
   // app code
   if GEraser.IsAvailable then begin
      GEraser.EraserEnd;
   end;
   GEraser.Free;


Please remember, Eraser is GPL'ed, honor that!

Labels: , ,

Tuesday, October 16, 2007

Auto-arranging the desktop

Total Commander is a file manager I use daily, and it's highly configurable. One feature very important to me is a copy/move queue that runs in the background, so that I can continue managing files while some are copied or moved. This queue always appears at position 0,0 on the screen though, which I find disturbing.

Since I like to train myself in the good old non-VCL non-RTL non-OO style myself from time to time, I wrote this little TCQueuePos.pas, which just continously tries to locate the window and moves it to the proper position if necessary.

The more I think about it, the more I like the idea of a more general kind of window clearance app which moves a bunch of windows into preferred positions (if you use two screens, you often have preferred positions for a bunch of small standard apps). No idea whether I find the time to do it, so I posted the file (link on filename above) LGPL'ed as a mini tutorial.

As a demonstration on how simple working with Desktop windows is, i've LGPL'ed and uploaded it (link on filename above). It compiles with Borland Delphi (the free Turbo Delphi edition, even the command line dcc32.exe, as well as the Win32 and Win64 versions of FreePascal).

Tuesday, July 03, 2007

Querying information from Amazons Webservices

Based on another question at German Delphi-PRAXiS (see here and here), I took out CollectionTemplater, the tool I wrote to easily generate comfortable collection classes, and added some stuff to search Amazons library. Supported download methods are WinInet (through the pkWinInet unit available here as well), Indy (if someone really cares to use that) and of course Synapse (my personal choice). XML handling as with all CollectionTemplater units can be either XMLLib, JclSimpleXml or SimpleXML.

How to use it?

program AmazonListTest;
{$APPTYPE CONSOLE}
uses snlProtoAmazonOnca;
var al: TAmazonList;
    i: integer;
begin
   al := TAmazonList.Create;
   al.DeveloperToken := ''; // fill in your token
   al.AssociateID := ''; // fill in your assoc. id
   if not al.QueryArtist('New%20Model%20Army')
    then WriteLn('What the ...?');
   if al.Count>0 then begin
      for i := 0 to Pred(al.Count)
       do WriteLn('This is great: ' + al[i].ProductName);
   end else WriteLn('Amazon doesn''t know good music!');
   al.Free;
end.


Oh, I nearly forgot: here's snlProtoAmazonOnca.pas.