Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-31 Thread Vinzent Hoefler
On Tuesday 30 October 2007 17:31, Inga Petuhhov wrote:
 A copy-paste from Python Shell:
  a = 1
  a

 1

  a = a + 0.4
  a

 1.3999

  a = a - 0.4
  a

 0.99989

  a == 1

 False

Or a bit more simple (and for some maybe even more surprising):

 1.0 == 0.4 - 0.4 + 1.0
True
 1.0 == 1.0 + 0.4 - 0.4
False

Floating points are not reals. Even simple commutative laws don't 
hold.


Vinzent.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

Or even better, give a clear problem description.


TASKS:

First, is to count number of words inside the document.
Second, is to count number of unique words inside the document.

INPUT:

Document format is using HTML-like format for storing articles. Here's 
the format:


DOC (contains an article)
 |- DOCID (contains article's ID)
 |- TITLE (contains article's title text)
 |- TEXT (contains article's content text)

CRITERIA:

A word criteria are:
- alphabetic (a..z) character sequence separated by whitespaces or 
hyphenation characters (space, tab, return, minus).
- character sequence that contains non alphabetic character is NOT 
considered as a word, ignored it.

- inside TITLE and TEXT tag, ignore anything inside DOCID.

Unique word criteria is case-insensitive. So word and Word is 
considered a same word.


EXAMPLE:

DOC
DOCIDTEMPO-022904-111/DOCID
TITLEThis is the article title./TITLE
TEXT
This is The article-content 123abc.
/TEXT
/DOC

would give result:

Number of words = 10
Number of unique words = 6

10 words are 5 words from inside TITLE tag and 5 words from inside TEXT 
tag. The unique words are: this, is, the, article, title., and 
content. 123abc. is ignored since it contains numbers.


The document may contain more than one article. Counting is done through 
out all articles found.


My program (using TStrings) requires about 0.4s to process the given 
document. :( Tested on the same machine using FPC v.2.0.4.


-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:

TStrings is meant for GUI purposes. It's design and implementation are
not optimized.


Then its our task to optimize it more (and more) so it could as fast as 
Perl. What I meant here is using standard or default FPC's 
classes/units. ;) I don't count any third parties class/units/library or 
non standard attempt here since it'd require extra effort, especially 
for newbies or newcomers (to FPC).


Of course, I know I can beat Perl using my own optimized TStrings 
written in assembler by hand mixed by pascal syntax. But, that's not the 
point. ;)




The point is that you are probably using the wrong class (I have not seen your 
code). To do unique word counts, a hash table is more suitable that a string list.


Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

TStrings is meant for GUI purposes. It's design and implementation are
not optimized.


Then its our task to optimize it more (and more) so it could as fast as 
Perl. What I meant here is using standard or default FPC's 
classes/units. ;) I don't count any third parties class/units/library or 
non standard attempt here since it'd require extra effort, especially 
for newbies or newcomers (to FPC).


Of course, I know I can beat Perl using my own optimized TStrings 
written in assembler by hand mixed by pascal syntax. But, that's not the 
point. ;)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Marco van de Voort
 I had never used Perl before. Until someone showed me Perl is very fast 
 for text processing (using its powerful regex), despite it's an 
 interpreted language. It even beat Delphi and FPC though both are 
 compiled language. A few lines Perl program almost two times faster than 
 a few pages pascal program.
 
 How can an interpreted language is faster than a compiled language (I 
 assume both has been optimized well and using the best algorithm)? Can 
 FPC improve its text processing related classes/units, so they can be 
 faster than Perl (as it should be, logically)? Especially the TStrings 
 class.

Perl is about regex. They use regex even for stuff where regexes aren't 
necessary.
Since Perl is so fixated on regex, it is likely the case where most time is
spent. Moreover, regexes are relative tight statemachines, and most of the
time of regex benchmarks is spent in it, and thus outside perl.

TStrings is meant for GUI purposes. It's design and implementation are not
optimized.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Marco van de Voort
  TStrings is meant for GUI purposes. It's design and implementation are
  not optimized.
 
 Then its our task to optimize it more (and more) so it could as fast as 
 Perl. What I meant here is using standard or default FPC's 
 classes/units. ;) I don't count any third parties class/units/library or 
 non standard attempt here since it'd require extra effort, especially 
 for newbies or newcomers (to FPC).

You can't separate performance from requirements. First define a problem,
then a solution. Not the other way around.

If you just want to show off, the easiest is simply making a FPC header to
pcre, it might be useful even.
 
 Of course, I know I can beat Perl using my own optimized TStrings 
 written in assembler by hand mixed by pascal syntax. But, that's not the 
 point. ;)

TString returns strings. A regex returns a boolean. This means that tstrings
must always copy strings.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Arrays of objects

2007-10-31 Thread Adrian Maier
Hello,

I'm seeking for advice about which is the best way to hold an array of
class instances
I need to access the elements using its position (like a regular
array) , and also i'd like
the structure to grow when I add more elements.

Fpc has  'dynamic arrays'  ,  and also there several classes like
TFPList,  TList
in RTL.Classes  . Also,  the FCL has the  contrns  unit which also contains
some classes that can be used for storing objects into memory.

At this point there are already too many options,  and I am unsure what to use.

The 'dynamic arrays'  are very close to what i'm looking for,  except
that I couldn't
find the documentation page of the SetLength procedure. In particular : what
happens if i call this procedure again for the same array  :  an does
it re-allocate
memory for the array  , or resizes its memory ?



Cheers,
Adrian Maier
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Speed

2007-10-31 Thread Jonas Maebe


On 31 Oct 2007, at 00:47, L wrote:

And I'm sure you know you can always use GOTO statements when you  
really need

speed out of loops


Actually, in current FPC versions that will more often than not cause  
slowdowns, because the compiler cannot optimize as well when goto's  
are used.



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-31 Thread Musan Antal
The discussion about PI reminds me another funny quote:

The primary purpose of the DATA statement is to give names to
constants; instead of referring to pi as 3.141592653589793 at every
appearance, the variable PI can be given that value with a DATA
statement and used instead of the longer form of the constant.  This
also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers

Oh, my GOD!
I hope, in the current eternity, no change in the value of pi might occur!
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:
If you just want to show off, the easiest is simply making a FPC 
header to

pcre, it might be useful even.


Making a header on top of other libraries written by other languages is 
showing that FPC is lack of powerful units/libraries. For some 
particular cases maybe it's alright. For example header over OS API, or 
over Apache, or over widgetsets (gtk, qt, wince, etc), or other common 
and huge libraries. But for basic or simple task like text processing, 
IMO we should provide it by ourselves (fpc). Maybe we should write our 
own pascal regex library that is more powerful than pcre, or at least 
equal. That way we could be more independent. ;)




To give you a head start, check out:
http://svn.freepascal.org/svn/fpc/trunk/packages/base/regexpr/

It needs testing and fixing.

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Jonas Maebe


On 31 Oct 2007, at 10:40, Bee wrote:

If you just want to show off, the easiest is simply making a FPC  
header to

pcre, it might be useful even.


Making a header on top of other libraries written by other  
languages is showing that FPC is lack of powerful units/libraries.


It merely means you don't want to waste time on rewriting a perfectly  
good library simply because of abstract language purity reasons. It  
is completely irrelevant in what language a library is written if it  
works well with your program and does what you want.



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

If you just want to show off, the easiest is simply making a FPC header to
pcre, it might be useful even.


Making a header on top of other libraries written by other languages is 
showing that FPC is lack of powerful units/libraries. For some 
particular cases maybe it's alright. For example header over OS API, or 
over Apache, or over widgetsets (gtk, qt, wince, etc), or other common 
and huge libraries. But for basic or simple task like text processing, 
IMO we should provide it by ourselves (fpc). Maybe we should write our 
own pascal regex library that is more powerful than pcre, or at least 
equal. That way we could be more independent. ;)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Matt Emson

Adrian Maier wrote:

Hello,

I'm seeking for advice about which is the best way to hold an array of
class instances
I need to access the elements using its position (like a regular
array) , and also i'd like
the structure to grow when I add more elements

TObjectList

If you want specific non type casted code, write a wrapper that exposes 
the obvious methods and properties:


type
  TMyObject = class
   public
   a: integer;
   end;


   TMyObjectListWrapper = class
   private
  flist: TObjectList;
  procedure SetItem(index: counter; item: TMyObject);
  function GetItem(index: integer): TMyObject;
public
   function Count: integer;
   function Add(item: TObject): integer;
   procedure Delete(index: integer);
   procedure Clear;
   property Items[index: integer]:TMyObject read GetItem write SetItem;
   end;

untested because I have no Pascal to compile with, but you get the jist.

M
  
___

fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

To give you a head start, check out:
http://svn.freepascal.org/svn/fpc/trunk/packages/base/regexpr/


You read my mind! I've just been thinking about to use fpc's regex unit. :D


It needs testing and fixing.


How is it compare with regex that comes from FPC 2.0.4? I still can't 
upgrade to fpc 2.2.0 for some particular reasons. ;)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Speed

2007-10-31 Thread Jilani Khaldi

I hear the Intel C compilers and Fortran compilers and Ada compilers are better
optimized for certain things since FPC/delphi are generally desinged for GUI
programming. ;-)


C/Fortran yes, Ada no; there exists no Intel Ada compiler.

False. There's no speed penalty for writing in Ada vs C. They use the
same Gnu compiler back-end, and thus the same assembler-level
optimizations. Identical algorithms implemented in the two languages
often produce indistinguishable performance.
There are cases where an Ada compiler can get better performance than
a C compiler, because the Ada compiler has more information to work
with.

--
Jilani KHALDI

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Jonas Maebe


On 31 Oct 2007, at 11:00, Bee wrote:

It merely means you don't want to waste time on rewriting a  
perfectly good library simply because of abstract language  
purity reasons. It is completely irrelevant in what language a  
library is written if it works well with your program and does  
what you want.


Yes. If C is very good, I won't use pascal (especially fpc) at the  
first place. :-P


Do you really not see the difference between
a) code already written and tested by others
b) code written by yourself

The regexp library is case 1. A program using that library is case 2.  
Case 1 can be written in C because the original author prefers C.  
Case 2 can be written in Pascal because you prefer Pascal. Language  
superiority does not enter the picture.



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (more pi fun)

2007-10-31 Thread Tom Verhoeff
On Tue, Oct 30, 2007 at 07:36:39PM +0200, Musan Antal wrote:
 The discussion about PI reminds me another funny quote:
 
 The primary purpose of the DATA statement is to give names to
 constants; instead of referring to pi as 3.141592653589793 at every
 appearance, the variable PI can be given that value with a DATA
 statement and used instead of the longer form of the constant.  This
 also simplifies modifying the program, should the value of pi change.
 -- FORTRAN manual for Xerox Computers

Here is another funny pi quote (appearing in a footnote in a book on
VLSI design):

pi = sqrt(10) for small values of pi

With apologies for the increasing off-topicness,

Tom
-- 
E-MAIL: T.Verhoeff @ TUE.NL | Dept. of Math.  Comp. Science
PHONE:  +31 40 247 41 25| Technische Universiteit Eindhoven
FAX:+31 40 247 54 04| PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee
It merely means you don't want to waste time on rewriting a perfectly 
good library simply because of abstract language purity reasons. It is 
completely irrelevant in what language a library is written if it works 
well with your program and does what you want.


Yes. If C is very good, I won't use pascal (especially fpc) at the first 
place. :-P


-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] fast text processing

2007-10-31 Thread Jeff Pohlmeyer
Heck, I'm not even a programmer, and this kludge is
about 25% faster than your perl script on my machine

program koleski;
{$MODE OBJFPC} {$H+}

uses classes, strings;

var
  f: text;
  s:ansistring;
  wc:longint=0;
  wl, ul:TStringList;
  i,n:LongInt;

begin
  assign(f, 'Koleksi.dat');
  reset(f);
  wl:=TStringList.Create();
  ul:=TStringList.Create();
  ul.Sorted:=true;
  ul.Duplicates:=dupIgnore;
  while not eof(f) do begin
readln(f,s);
n:=length(s);
if (n0) then begin
StrLower(@s[1]);
  if (s[1]='') then begin
if StrLComp(@s[1], 'title',7) = 0 then begin
  delete(s,1,7);
end else continue;
  end;
  for i:=1 to n do if not (s[i] in ['a'..'z','0'..'9']) then begin
if ( s[i]  '' ) then begin
  s[i]:=#10
end else begin
  s[i]:=#0;
  SetLength(s,StrLen(@s[1]));
  break;
end;
  end;
  wl.Text:=s;
  for i:=0 to wl.Count-1 do begin
s:=wl[i];
for n:=1 to length(s) do if (s[n] in ['0'..'9']) then begin
  s:='';
  break;
end;
if (s'') then begin
  inc(wc);
  ul.Add(s);
end;
  end;
end;
  end;
  close(f);
  WriteLn('Word count:',wc, #10'Unique word count:', ul.Count);
end.


 - Jeff
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

Heck, I'm not even a programmer, and this kludge is
about 25% faster than your perl script on my machine


Nope. It's still more or less twice slower. :-D

[EMAIL PROTECTED]:~$ time perl koleksi.perl

Word count: 126944
Unique word count: 11793

real0m0.208s
user0m0.204s
sys 0m0.004s

[EMAIL PROTECTED]:~$ time ./koleksi2

Word count:126944
Unique word count:11793

real0m0.452s
user0m0.432s
sys 0m0.016s

-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Adrian Maier
On 10/31/07, Matt Emson [EMAIL PROTECTED] wrote:
 Adrian Maier wrote:
  Hello,
 
  I'm seeking for advice about which is the best way to hold an array of
  class instances
  I need to access the elements using its position (like a regular
  array) , and also i'd like
  the structure to grow when I add more elements
 TObjectList

I am aware that TObjectList is one of the possible ways.
But I was hoping to get a better understanding about the purpose of these
various classes or types of array ,  and more importantly what are the
drawbacks .

Is there really no wiki page , tutorial, anything  that provides an overview of
the collections and types of arrays that FPC has ?


-- 
Adrian Maier
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] fast text processing

2007-10-31 Thread Jeff Pohlmeyer
  this kludge is about 25% faster than your perl script
  on my machine

 Nope. It's still more or less twice slower. :-D


I guess it depends on the hardware:

% time koleksi.pl   # perl
Word count: 126944
Unique word count: 11793

real0m1.019s
user0m0.992s
sys 0m0.028s


% time koleksi   # fpc
Word count:126944
Unique word count:11793

real0m0.817s
user0m0.784s
sys 0m0.020s


AMD-K6-700 / SuSE-10.3 / Linux-2.6.22  / perl-5.8.8 / fpc-2.2.0


 - Jeff
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Jeff Pohlmeyer schreef:

this kludge is about 25% faster than your perl script
on my machine



Nope. It's still more or less twice slower. :-D



I guess it depends on the hardware:

% time koleksi.pl   # perl
Word count: 126944
Unique word count: 11793

real0m1.019s
user0m0.992s
sys 0m0.028s


% time koleksi   # fpc
Word count:126944
Unique word count:11793

real0m0.817s
user0m0.784s
sys 0m0.020s


AMD-K6-700 / SuSE-10.3 / Linux-2.6.22  / perl-5.8.8 / fpc-2.2.0




Thanks Jeff, for writing that parser code, I am not good in doing that.

I made it three times as fast on my computer (windows 2000, fpc 2.3.1, P4 1.5 Ghz) 
using a hashlist for the unique word count. Using a larger textbuf gave an 
additional 10% speed up:


program project1;
{$MODE OBJFPC} {$H+}

uses classes, strings, contnrs;

const
  bufsize = $1FFF;

var
  f: text;
  s:ansistring;
  wc:longint=0;
  wl:TStringList;
  uhl: TFPStringHashTable;
  i,n:LongInt;
  textbuf: array[0..bufsize-1] of byte;

begin
  assign(f, 'Koleksi.dat');
  reset(f);
  SetTextBuf(f, textbuf, sizeof(textbuf));
  wl:=TStringList.Create();
  uhl:=TFPStringHashTable.Create;
  while not eof(f) do begin
readln(f,s);
n:=length(s);
if (n0) then begin
StrLower(@s[1]);
  if (s[1]='') then begin
if StrLComp(@s[1], 'title',7) = 0 then begin
  delete(s,1,7);
end else continue;
  end;
  for i:=1 to n do if not (s[i] in ['a'..'z','0'..'9']) then begin
if ( s[i]  '' ) then begin
  s[i]:=#10
end else begin
  s[i]:=#0;
  SetLength(s,StrLen(@s[1]));
  break;
end;
  end;
  wl.Text:=s;
  for i:=0 to wl.Count-1 do begin
s:=wl[i];
for n:=1 to length(s) do if (s[n] in ['0'..'9']) then begin
  s:='';
  break;
end;
if (s'') then begin
  inc(wc);
  if uhl.Find(s) = nil then
uhl.Add(s,'');
end;
  end;
end;
  end;
  close(f);
  WriteLn('Word count:',wc, #10'Unique word count:', uhl.Count);
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

AMD-K6-700 / SuSE-10.3 / Linux-2.6.22  / perl-5.8.8 / fpc-2.2.0


Probably because the different fpc version, no? I'm using fpc 2.0.4. 
However, this is a good news. :)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Marco van de Voort
  If you just want to show off, the easiest is simply making a FPC header to
  pcre, it might be useful even.
 
 Someone had worked on it using Delphi7 and PCRE. A little optimization 
 is done on the TStringList, it uses CompareText instead of CompareStr 
 for text comparison. It does faster than my program (using fpc and the 
 default TStringList), but still about 40% slower than Perl. Plus, the 
 program depends on PCRE library. :(

(Probably the other way around, but that breaks MBCS (Delphi) and UTF-8(FPC)
compability, and the internationalization of your GUI. So that is not
something safe to do)

You are not the first to optimize TStringList in this way, and will not the
last. There are reasons why TStringList is as it is.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] fast text processing

2007-10-31 Thread Jeff Pohlmeyer
 the easiest is simply making a FPC header to
 pcre, it might be useful even.

I did that, once upon a time...

  http://www.hotlinkfiles.com/files/526004_qpvr0/pcre-fpc.tar.gz


 -Jeff
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee
I made it three times as fast on my computer (windows 2000, fpc 2.3.1, 
P4 1.5 Ghz) using a hashlist for the unique word count. Using a larger 
textbuf gave an additional 10% speed up:


Arrrggg, I hate myself for not able to upgrade to fpc v.2.2.0! I 
can't find TFPStringHashTable on fpc v.2.0.4! :((


-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Joao Morais

Adrian Maier wrote:

On 10/31/07, Matt Emson [EMAIL PROTECTED] wrote:

Adrian Maier wrote:

Hello,

I'm seeking for advice about which is the best way to hold an array of
class instances
I need to access the elements using its position (like a regular
array) , and also i'd like
the structure to grow when I add more elements

TObjectList


I am aware that TObjectList is one of the possible ways.
But I was hoping to get a better understanding about the purpose of these
various classes or types of array ,  and more importantly what are the
drawbacks .

Is there really no wiki page , tutorial, anything  that provides an overview of
the collections and types of arrays that FPC has ?


You can use dynamic arrays, they work like an ansi string:

var
  VArray: array of TSomeClass;
begin
  SetLength(VArray, 10);
  // now you have VArray[0] .. VArray[9];
  SetLength(VArray, 20);
  // now you have [0] .. [19];
  // Length(VArray) = 20
  // for I := 0 to Pred(Length(VArray)) is a valid statement

They are reference counted, just like ansi strings, ie don't worry about 
memory leakages.


--
Joao Morais
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Marco van de Voort
 Adrian Maier wrote:
VArray: array of TSomeClass;
 begin
SetLength(VArray, 10);
// now you have VArray[0] .. VArray[9];
SetLength(VArray, 20);
// now you have [0] .. [19];
// Length(VArray) = 20
// for I := 0 to Pred(Length(VArray)) is a valid statement
 
 They are reference counted, just like ansi strings, ie don't worry about 
 memory leakages.

... Of the array itself. The objects it contains is another matter.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Adrian Maier
On 10/31/07, Joao Morais [EMAIL PROTECTED] wrote:
 Adrian Maier wrote:
  On 10/31/07, Matt Emson [EMAIL PROTECTED] wrote:
  Adrian Maier wrote:
  Hello,
 
  I'm seeking for advice about which is the best way to hold an array of
  class instances
  I need to access the elements using its position (like a regular
  array) , and also i'd like
  the structure to grow when I add more elements
  TObjectList
 
  I am aware that TObjectList is one of the possible ways.
  But I was hoping to get a better understanding about the purpose of these
  various classes or types of array ,  and more importantly what are the
  drawbacks .
 
  Is there really no wiki page , tutorial, anything  that provides an 
  overview of
  the collections and types of arrays that FPC has ?

 You can use dynamic arrays, they work like an ansi string:

 var
VArray: array of TSomeClass;
 begin
SetLength(VArray, 10);
// now you have VArray[0] .. VArray[9];
SetLength(VArray, 20);
// now you have [0] .. [19];
// Length(VArray) = 20
// for I := 0 to Pred(Length(VArray)) is a valid statement

 They are reference counted, just like ansi strings, ie don't worry about
 memory leakages.

The detail that is not crystal clear to me is  :  after the first SetLength
and  i set the first 3  elements  ,   is it *guaranteed* that the
second SetLength
leaves those first 3 elements  untouched ?

That's what i meant by resize as opposed to  reallocate . Reallocation
could occur in some other place in memory , leading to loosing the
original contents.I have actually tested it with a small program,  but since
i've been able to access indexes way beyond the allocated number of elements
before getting the program killed i   want to be sure that i understand the
proper use of dynamic arrays.


Thanks  Joao  !


-- 
Adrian Maier
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Matt Emson

Marco van de Voort wrote:

Adrian Maier wrote:
   VArray: array of TSomeClass;
begin
   SetLength(VArray, 10);
   // now you have VArray[0] .. VArray[9];
   SetLength(VArray, 20);
   // now you have [0] .. [19];
   // Length(VArray) = 20
   // for I := 0 to Pred(Length(VArray)) is a valid statement

They are reference counted, just like ansi strings, ie don't worry about 
memory leakages.



... Of the array itself. The objects it contains is another matter.


Which is why TObjectList is a good choice: TObjectList.Create(True) 
makes all instances added to the list owned by the list and free'd when 
the list is free'd. TObjectList also manages the allocation/deallocation 
and size for you.


M
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Joao Morais

Marco van de Voort wrote:

Adrian Maier wrote:
   VArray: array of TSomeClass;
begin
   SetLength(VArray, 10);
   // now you have VArray[0] .. VArray[9];
   SetLength(VArray, 20);
   // now you have [0] .. [19];
   // Length(VArray) = 20
   // for I := 0 to Pred(Length(VArray)) is a valid statement

They are reference counted, just like ansi strings, ie don't worry about 
memory leakages.


... Of the array itself. The objects it contains is another matter.


Ah, yes, forgot to mention this. I usually use dyn arrays to manage 
objects owned by other lists or objects.


--
Joao Morais
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Lourival Mendes
Dear Joao,

   I do beleive that the SetLength only resize the array, ie: The
Vetor has 3 elements like:

   Vetor[0]:= 1
   Vetor[1]:= 2
   Vetor[2]:= 3
  And then eu want the same variable but with only 2 element, then

   SetLength(Vetor, 2)
   Vetor[0]:= 1
   Vetor[1]:= 2

   As you can see you don't lose the first 2, After that you want 4
elements on the same variable:

   SetLength(Vetor, 4)

   If you print the variable, before associate any value to it you will get:

   Vetor[0]:= 1
   Vetor[1]:= 2
   Vetor[2]:= 0
   Vetor[3]:= 0

  Hope it helped

Lourival

2007/10/31, Joao Morais [EMAIL PROTECTED]:
 Marco van de Voort wrote:
  Adrian Maier wrote:
 VArray: array of TSomeClass;
  begin
 SetLength(VArray, 10);
 // now you have VArray[0] .. VArray[9];
 SetLength(VArray, 20);
 // now you have [0] .. [19];
 // Length(VArray) = 20
 // for I := 0 to Pred(Length(VArray)) is a valid statement
 
  They are reference counted, just like ansi strings, ie don't worry about
  memory leakages.
 
  ... Of the array itself. The objects it contains is another matter.

 Ah, yes, forgot to mention this. I usually use dyn arrays to manage
 objects owned by other lists or objects.

 --
 Joao Morais
 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-pascal



-- 
Lourival J. Mendes Neto
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Joao Morais

Lourival Mendes wrote:

   SetLength(Vetor, 2)
   Vetor[0]:= 1
   Vetor[1]:= 2

   As you can see you don't lose the first 2, After that you want 4
elements on the same variable:

   SetLength(Vetor, 4)

   If you print the variable, before associate any value to it you will get:

   Vetor[0]:= 1
   Vetor[1]:= 2
   Vetor[2]:= 0
   Vetor[3]:= 0


I assume the same based on the rtl internals -- except that you cannot 
assume values from a newly allocated area (except if you are dealing 
with objects)


--
Joao Morais

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
On 31/10/2007, Bee [EMAIL PROTECTED] wrote:

 Vincent said it was 3 times faster. I expected the result would be about
 0.10s. Or am I wrong?

Maybe that's machine dependent I'll try the one without the hash
table to see the difference.  Otherwise, lets just compare the sys
time and say it's 16x faster. ;-)


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:

[EMAIL PROTECTED]:word_parser$ time ./project1
Word count:126944
Unique word count:11793

real0m0.185s
user0m0.140s
sys 0m0.000s

[EMAIL PROTECTED]:word_parser$ time perl project1.perl
Word count: 126944
Unique word count: 11793

real0m0.281s
user0m0.244s
sys 0m0.016s


Vincent said it was 3 times faster. I expected the result would be about 
0.10s. Or am I wrong?


Maybe I have a relatively slow computer, so I get more speedup. Keep in mind, that 
disk time is constant.


So for example, total time is disk time + processing time
For me:
StringList: 10 + 50 = 60
Hashtable: 10 + 10 = 20
Speedup: 3 times

For Graeme with his faster computer (2x processor time):
StringList: 10 + 25 = 35
Hashtable: 10 + 5 = 15
Speedup: 2.3

Please choose appropiate number to get to the result :-)

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:

[EMAIL PROTECTED]:word_parser$ time ./project1
Word count:126944
Unique word count:11793

real0m0.185s
user0m0.140s
sys 0m0.000s

[EMAIL PROTECTED]:word_parser$ time perl project1.perl
Word count: 126944
Unique word count: 11793

real0m0.281s
user0m0.244s
sys 0m0.016s


Vincent said it was 3 times faster. I expected the result would be about 
0.10s. Or am I wrong?




It was three times faster than the string list version of Jeff. I don't have a perl 
interpreter :-).


Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
On 31/10/2007, Vincent Snijders [EMAIL PROTECTED] wrote:

 Maybe I have a relatively slow computer, so I get more speedup. Keep in mind, 
 that
 disk time is constant.


I'm also not sure if FPC compiler parameters where used. I did.
I compiled as:fpc project1.pas


Anyway, here is the Hash Table vs No Hash Table results.  Quite a
difference in speed when using the hash table.


[EMAIL PROTECTED]:word_parser$ time ./project1_nohashtable
Word count:126944
Unique word count:11793

real0m0.291s
user0m0.276s
sys 0m0.004s


[EMAIL PROTECTED]:word_parser$ time ./project1
Word count:126944
Unique word count:11793

real0m0.196s
user0m0.132s
sys 0m0.008s


[EMAIL PROTECTED]:word_parser$ time perl ./project1.perl
Word count: 126944
Unique word count: 11793

real0m0.292s
user0m0.268s
sys 0m0.000s
[EMAIL PROTECTED]:word_parser$




Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Joao Morais

Adrian Maier wrote:

On 10/31/07, Joao Morais [EMAIL PROTECTED] wrote:

Adrian Maier wrote:

On 10/31/07, Matt Emson [EMAIL PROTECTED] wrote:

Adrian Maier wrote:

Hello,

I'm seeking for advice about which is the best way to hold an array of
class instances
I need to access the elements using its position (like a regular
array) , and also i'd like
the structure to grow when I add more elements

TObjectList

I am aware that TObjectList is one of the possible ways.
But I was hoping to get a better understanding about the purpose of these
various classes or types of array ,  and more importantly what are the
drawbacks .

Is there really no wiki page , tutorial, anything  that provides an overview of
the collections and types of arrays that FPC has ?

You can use dynamic arrays, they work like an ansi string:

var
   VArray: array of TSomeClass;
begin
   SetLength(VArray, 10);
   // now you have VArray[0] .. VArray[9];
   SetLength(VArray, 20);
   // now you have [0] .. [19];
   // Length(VArray) = 20
   // for I := 0 to Pred(Length(VArray)) is a valid statement

They are reference counted, just like ansi strings, ie don't worry about
memory leakages.


The detail that is not crystal clear to me is  :  after the first SetLength
and i set the first 3 elements, is it *guaranteed* that the
second SetLength leaves those first 3 elements untouched?


I don't use dyn array realocation by myself, but seeing this piece of 
code I'd assume yes:


procedure TFPList.SetCapacity(NewCapacity: Integer);
begin
  If (NewCapacity  FCount) or (NewCapacity  MaxListSize) then
 Error (SListCapacityError, NewCapacity);
  if NewCapacity = FCapacity then
exit;
  ReallocMem(FList, SizeOf(Pointer)*NewCapacity);
  FCapacity := NewCapacity;
end;

--
Joao Morais
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
Well done Vincent!!  :-)  I can confirm your results...


[EMAIL PROTECTED]:word_parser$ time ./project1
Word count:126944
Unique word count:11793

real0m0.185s
user0m0.140s
sys 0m0.000s

[EMAIL PROTECTED]:word_parser$ time perl project1.perl
Word count: 126944
Unique word count: 11793

real0m0.281s
user0m0.244s
sys 0m0.016s


Hardware:  Intel P4 CPU 2.40GHz with 1Gig RAM
FPC Compiler:   v2.2.0


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

[EMAIL PROTECTED]:word_parser$ time ./project1
Word count:126944
Unique word count:11793

real0m0.185s
user0m0.140s
sys 0m0.000s

[EMAIL PROTECTED]:word_parser$ time perl project1.perl
Word count: 126944
Unique word count: 11793

real0m0.281s
user0m0.244s
sys 0m0.016s


Vincent said it was 3 times faster. I expected the result would be about 
0.10s. Or am I wrong?


-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Marco van de Voort
 On 31/10/2007, Vincent Snijders [EMAIL PROTECTED] wrote:
 
  Maybe I have a relatively slow computer, so I get more speedup. Keep in 
  mind, that
  disk time is constant.
 
 
 I'm also not sure if FPC compiler parameters where used. I did.
 I compiled as:fpc project1.pas

It could be wise to add -O3 for anything considered a benchmark :-)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Marco van de Voort
 On 10/31/07, Joao Morais [EMAIL PROTECTED] wrote:
  They are reference counted, just like ansi strings, ie don't worry about
  memory leakages.
 
 The detail that is not crystal clear to me is  :  after the first SetLength
 and  i set the first 3  elements  ,   is it *guaranteed* that the
 second SetLength
 leaves those first 3 elements  untouched ?

Yes. But they can be copied, so address to them might be invalid.
 
 That's what i meant by resize as opposed to  reallocate . Reallocation
 could occur in some other place in memory , leading to loosing the
 original contents.  

It does resize if possible, reallocate (and copy the original data as far as
it fits) else.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee
I had never used Perl before. Until someone showed me Perl is very fast 
for text processing (using its powerful regex), despite it's an 
interpreted language. It even beat Delphi and FPC though both are 
compiled language. A few lines Perl program almost two times faster than 
a few pages pascal program.


Alright everyone. The answers are enough. Now I can say confidently that 
pascal (fpc v.2.2) is FASTER than Perl, including in text processing. ;)


Thank you very much to everyone who involves in this thread. :)

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-31 Thread Germán Pablo Gentile - PetroBox

El mar, 30-10-2007 a las 19:36 +0200, Musan Antal escribió:
  
 Oh, my GOD!
 I hope, in the current eternity, no change in the value of pi might
 occur!

I bet the circles will never will be the same if that happens.:P

 ___
 fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-pascal
-- 
Germán Pablo Gentile - PetroBox [EMAIL PROTECTED]
Petrobox

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Speed

2007-10-31 Thread Vinzent Hoefler
On Wednesday 31 October 2007 12:35, Daniël Mantione wrote:

 Further, it is unknown how well the GCC backend optimizes Ada
 language constructs as it is primarily designed for the C language.

Well enough. In other words, optimization is about the same - given 
fairly equivalent code.

The main difference is that the Ada compiler gets its knowledge from the 
variable declarations, while the C compiler gets it from the code.


Vinzent.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Marco van de Voort
[ Charset ISO-8859-1 unsupported, converting... ]
  I had never used Perl before. Until someone showed me Perl is very fast 
  for text processing (using its powerful regex), despite it's an 
  interpreted language. It even beat Delphi and FPC though both are 
  compiled language. A few lines Perl program almost two times faster than 
  a few pages pascal program.
 
 Alright everyone. The answers are enough. Now I can say confidently that 
 pascal (fpc v.2.2) is FASTER than Perl, including in text processing. ;)
 
 Thank you very much to everyone who involves in this thread. :)

I don't think that everybody that saw:

http://shootout.alioth.debian.org/gp4/benchmark.php?test=alllang=allcalc=Calculatexfullcpu=1xmem=0.5xloc=0binarytrees=1chameneos=0message=0fannkuch=1fasta=1knucleotide=1mandelbrot=1meteor=0nbody=1nsieve=1nsievebits=1partialsums=1pidigits=1recursive=1regexdna=1revcomp=1spectralnorm=1hello=0sumcol=1

ever doubted that.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
On 31/10/2007, Marco van de Voort [EMAIL PROTECTED] wrote:

 It could be wise to add -O3 for anything considered a benchmark :-)


It squeezed another 0.015s out of the time making it even faster. :-)


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Arrays of objects

2007-10-31 Thread Adrian Maier
On 10/31/07, Marco van de Voort [EMAIL PROTECTED] wrote:
  On 10/31/07, Joao Morais [EMAIL PROTECTED] wrote:
   They are reference counted, just like ansi strings, ie don't worry about
   memory leakages.
 
  The detail that is not crystal clear to me is  :  after the first SetLength
  and  i set the first 3  elements  ,   is it *guaranteed* that the
  second SetLength
  leaves those first 3 elements  untouched ?

 Yes. But they can be copied, so address to them might be invalid.

  That's what i meant by resize as opposed to  reallocate . Reallocation
  could occur in some other place in memory , leading to loosing the
  original contents.

 It does resize if possible, reallocate (and copy the original data as far as
 it fits) else.

Thanks for the info!


-- 
Adrian Maier
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
On 31/10/2007, Bee [EMAIL PROTECTED] wrote:

 Alright everyone. The answers are enough. Now I can say confidently that
 pascal (fpc v.2.2) is FASTER than Perl, including in text processing. ;)

 Thank you very much to everyone who involves in this thread. :)


That was fun!!! :-0  So what's the task for tomorrow? ;-)


Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Marco van de Voort schreef:

[ Charset ISO-8859-1 unsupported, converting... ]
I had never used Perl before. Until someone showed me Perl is very fast 
for text processing (using its powerful regex), despite it's an 
interpreted language. It even beat Delphi and FPC though both are 
compiled language. A few lines Perl program almost two times faster than 
a few pages pascal program.
Alright everyone. The answers are enough. Now I can say confidently that 
pascal (fpc v.2.2) is FASTER than Perl, including in text processing. ;)


Thank you very much to everyone who involves in this thread. :)


I don't think that everybody that saw:

http://shootout.alioth.debian.org/gp4/benchmark.php?test=alllang=allcalc=Calculatexfullcpu=1xmem=0.5xloc=0binarytrees=1chameneos=0message=0fannkuch=1fasta=1knucleotide=1mandelbrot=1meteor=0nbody=1nsieve=1nsievebits=1partialsums=1pidigits=1recursive=1regexdna=1revcomp=1spectralnorm=1hello=0sumcol=1

ever doubted that.


But people who have seen
http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdnalang=all
may have doubted that.

I wonder where fpc would end up in that list,
A: if it uses its own regexpr parser (atm not good enough)
B: if it uses Jeff's header translations for pcre

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:

But people who have seen
http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdnalang=all 


may have doubted that.


Vincent, are we connected or what?! I was about to post the very exact 
URL! :-D



I wonder where fpc would end up in that list,
A: if it uses its own regexpr parser (atm not good enough)
B: if it uses Jeff's header translations for pcre


I prefer it would use fpc own regexpr unit instead of using other 
language libraries. IMO, it'd show the power of pascal (fpc) by itself. ;)




Sure, but as Jonas pointed out it is better to use a good library than the write a 
bad library yourself. Feel free to improve the regexpr unit, if you want it to be used.


Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Henry Vermaak
On 31/10/2007, Graeme Geldenhuys [EMAIL PROTECTED] wrote:

 That was fun!!! :-0  So what's the task for tomorrow? ;-)

for tomorrow the homework is:  improve fpc regexp capability and get
fpc in the top 5 on the regex-dna shootout ratings ;)



 Regards,
   - Graeme -

henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee
Sure, but as Jonas pointed out it is better to use a good library than 
the write a bad library yourself. 


And someone would claim that the speed comes from the library (c?), not 
from pascal. :P It's a LANGUAGE shootout btw, not LIBRARY shootout. 
Maybe you had forgotten that. ;)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Bee schreef:
Sure, but as Jonas pointed out it is better to use a good library than 
the write a bad library yourself. 


And someone would claim that the speed comes from the library (c?), not 
from pascal. :P It's a LANGUAGE shootout btw, not LIBRARY shootout. 
Maybe you had forgotten that. ;)




A. That is not a problem. A couple of other, non-c participants use pcre.
B. The same is done with pidigits.
C. It shows that fpc has good interoperability.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vinzent Hoefler
On Wednesday 31 October 2007 14:19, Bee wrote:
  Sure, but as Jonas pointed out it is better to use a good library
  than the write a bad library yourself.

 And someone would claim that the speed comes from the library (c?),
 not

 from pascal. :P It's a LANGUAGE shootout btw, not LIBRARY shootout.

 Maybe you had forgotten that. ;)

Well, considering that perl's or Python's speed greatly rely on the 
underlying C-implementation of (at least) particular functionality, all 
those comparisons basically boil down to C vs. C, anyway. Or don't 
they?

;)


Vinzent.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee

A. That is not a problem. A couple of other, non-c participants use pcre.


I myself would consider them lacks of the language advantage on their own.


B. The same is done with pidigits.
C. It shows that fpc has good interoperability.


We could submit more than one programs, one using fpc own regepxr unit, 
another using pcre. This way we would also implicitly/indirectly 
compares regepxr performance between fpc own regexpr against other 
libraries, besides the good interoperability of fpc. ;)


-Bee-

has Bee.ography at:
http://beeography.wordpress.com
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Bee
Well, considering that perl's or Python's speed greatly rely on the 
underlying C-implementation of (at least) particular functionality, all 
those comparisons basically boil down to C vs. C, anyway. Or don't 
they?


Exactly! That's why I prefer to use fpc own regexpr unit. :)

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Florian Klaempfl
Vincent Snijders schrieb:
 Jeff Pohlmeyer schreef:
 this kludge is about 25% faster than your perl script
 on my machine

 Nope. It's still more or less twice slower. :-D


 I guess it depends on the hardware:

 % time koleksi.pl   # perl
 Word count: 126944
 Unique word count: 11793

 real0m1.019s
 user0m0.992s
 sys 0m0.028s


 % time koleksi   # fpc
 Word count:126944
 Unique word count:11793

 real0m0.817s
 user0m0.784s
 sys 0m0.020s


 AMD-K6-700 / SuSE-10.3 / Linux-2.6.22  / perl-5.8.8 / fpc-2.2.0


 
 Thanks Jeff, for writing that parser code, I am not good in doing that.
 
 I made it three times as fast on my computer (windows 2000, fpc 2.3.1,
 P4 1.5 Ghz) using a hashlist for the unique word count. Using a larger
 textbuf gave an additional 10% speed up:
 
 program project1;
 {$MODE OBJFPC} {$H+}
 
 uses classes, strings, contnrs;
 
 const
   bufsize = $1FFF;
 
 var
   f: text;
   s:ansistring;
   wc:longint=0;
   wl:TStringList;
   uhl: TFPStringHashTable;
   i,n:LongInt;
   textbuf: array[0..bufsize-1] of byte;
 
 begin
   assign(f, 'Koleksi.dat');
   reset(f);
   SetTextBuf(f, textbuf, sizeof(textbuf));
   wl:=TStringList.Create();
   uhl:=TFPStringHashTable.Create;
   while not eof(f) do begin
 readln(f,s);
 n:=length(s);
 if (n0) then begin
 StrLower(@s[1]);
   if (s[1]='') then begin
 if StrLComp(@s[1], 'title',7) = 0 then begin
   delete(s,1,7);
 end else continue;
   end;
   for i:=1 to n do if not (s[i] in ['a'..'z','0'..'9']) then begin
 if ( s[i]  '' ) then begin
   s[i]:=#10
 end else begin
   s[i]:=#0;
   SetLength(s,StrLen(@s[1]));

Why not SetLength(s,i)? StrLen is _very_ expensive. I don't see a way
how another #0 can be before.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Florian Klaempfl schreef:

Vincent Snijders schrieb:

Jeff Pohlmeyer schreef:
  s[i]:=#0;
  SetLength(s,StrLen(@s[1]));


Why not SetLength(s,i)? StrLen is _very_ expensive. I don't see a way
how another #0 can be before.


That is right, I am working on a version which does not do that anymore.

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Speed

2007-10-31 Thread Jonas Maebe


On 31 Oct 2007, at 19:11, L wrote:


Further, it is unknown how well the GCC backend optimizes Ada
language constructs as it is primarily designed for the C language.


I assumed that people used not just GNU Ada compilers.. for serious  
work.

But I'm not sure.

For example, what do Airplanes use? GNU?
I'd laugh if Richard Stallman controlled the Boeing and rocket  
ships ;-)


Sorry for flamebait.


Please use the fpc-other list for things like that.


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Mattias Gaertner
On Wed, 31 Oct 2007 13:56:04 +0100 (CET)
[EMAIL PROTECTED] (Marco van de Voort) wrote:

 [ Charset ISO-8859-1 unsupported, converting... ]
   I had never used Perl before. Until someone showed me Perl is
   very fast for text processing (using its powerful regex), despite
   it's an interpreted language. It even beat Delphi and FPC though
   both are compiled language. A few lines Perl program almost two
   times faster than a few pages pascal program.
  
  Alright everyone. The answers are enough. Now I can say confidently
  that pascal (fpc v.2.2) is FASTER than Perl, including in text
  processing. ;)
  
  Thank you very much to everyone who involves in this thread. :)
 
 I don't think that everybody that saw:
 
 http://shootout.alioth.debian.org/gp4/benchmark.php?test=alllang=allcalc=Calculatexfullcpu=1xmem=0.5xloc=0binarytrees=1chameneos=0message=0fannkuch=1fasta=1knucleotide=1mandelbrot=1meteor=0nbody=1nsieve=1nsievebits=1partialsums=1pidigits=1recursive=1regexdna=1revcomp=1spectralnorm=1hello=0sumcol=1
 
 ever doubted that.

Does someone know, why java 6 -server is that fast?


Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Speed

2007-10-31 Thread Jilani Khaldi

For example, what do Airplanes use? GNU?
Ada compilers must be certified, so if you are developing software for 
avionics *you have* to write your software with a compiler certified for 
avionics development.

JK

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread L
  Well, considering that perl's or Python's speed greatly rely on the 
  underlying C-implementation of (at least) particular functionality, all 
  those comparisons basically boil down to C vs. C, anyway. Or don't 
  they?
 
 Exactly! That's why I prefer to use fpc own regexpr unit. :)
 
 -Bee-
 

Or you can use TRegexp or regexp2.pas units..

But from my testing, TRegexp is a bit slow on big files.

Not sure if the latest TRegexp is faster:

http://www.regexpstudio.com/TRegExpr/TRegExpr.html


L505
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread L
  Word count: 126944
  Unique word count: 11793
 
  real0m0.281s
  user0m0.244s
  sys 0m0.016s


Can someone do a test for 5 minutes of parsing and see if things slow down or
speed up for one of the programs?

That takes away process load time too..

example: the time it takes to fork the process.

Not sure if perl scripts are initially faster since you don't have to fork a
process, assuming perl is already in memory waiting for the script.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread L
   Word count: 126944
   Unique word count: 11793
  
   real0m0.281s
   user0m0.244s
   sys 0m0.016s
 

 Can someone do a test for 5 minutes of parsing

Rather I mean can someone do a more realistic test such as parsing 1500 files
instead of one single file. At least in my line of work, I never parse one
single file.. it is usually about 1500 or more at a time.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Daniël Mantione


Op Wed, 31 Oct 2007, schreef Vincent Snijders:

 Florian Klaempfl schreef:
  Vincent Snijders schrieb:
  
  Why not SetLength(s,i)? StrLen is _very_ expensive. I don't see a way
  how another #0 can be before.
 
 No more strlen:
 http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=1432

One more possible speedup: Why are you using strlower and strlcomp instead 
of lowercase/pos? The latter ones are probably faster and they don't care 
of code pages which are not relevant in this example.

Daniël___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] fast text processing

2007-10-31 Thread Vincent Snijders

Florian Klaempfl schreef:

Vincent Snijders schrieb:

Why not SetLength(s,i)? StrLen is _very_ expensive. I don't see a way
how another #0 can be before.


No more strlen:
http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=1432

Vincent
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] When Pascal code is too fast

2007-10-31 Thread Marc Santhoff
Am Donnerstag, den 01.11.2007, 00:45 +0200 schrieb ik:
 Hi List,
 
 I have a weird problem. the fpWrite is too slow for FPC code. When
 I have the same exact code in C that writes a big amount of buffers of
 the same size with the same content. It seems that the fpWrite is way
 too fast, and the can't handle another call in the loop, and I need to
 slow down the loop using usleep.
 At the beginning I thought that it was a problem with fpWrite, so I
 created my own binding, but still the problem is the same.
 
 Except then the fact that it seems that FPC is much faster the GCC,
 any other ideas for such a behavior and what might be the reasons for
 it ?
 
 A POC for such code btw, can be as follows:
 
 Pascal:
 ...
 while not EOF(f) do
   begin
   readln(f,s);
   fpwrite(f2, S[0], length(S));
   end;
 
 
 C:
 ...
 while (! feof(f)) {
   s_size = fread(f, s, MAX_BUFFER);
   write(f2, s, s_size);
 }
 ...

What error do you get? Lastly I had something similar with fpc writing
to fast to a non-blocking stderr channel. I haven't had time to do for
my code, but if you get ressource temporartily unavailable-like errors
switching the file to blocking mode might help.

Something like

fcntl(fileno(stderr), F_GETFL)  O_NONBLOCK

or the pascal equivalent should do.

HTH,
Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fast text processing

2007-10-31 Thread Graeme Geldenhuys
On 01/11/2007, Vincent Snijders [EMAIL PROTECTED] wrote:

 No more strlen:
 http://www.hu.freepascal.org/fpcircbot/cgipastebin?msgid=1432


Wow, that version improved quite a bit from the previous one!!

[EMAIL PROTECTED]:word_parser$ time ./project1_fast
Word count:126944
Unique word count:11793

real0m0.107s
user0m0.100s
sys 0m0.000s


[EMAIL PROTECTED]:word_parser$ time perl ./project1.perl
Word count: 126944
Unique word count: 11793

real0m0.271s
user0m0.248s
sys 0m0.008s



Regards,
  - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal