Recent

Author Topic: What is the FASTEST Computer Language? 45 Languages Tested!  (Read 32230 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #45 on: August 22, 2021, 05:36:09 pm »
Interesting idea. I also had such idea, when wanted to implement closures by myself. They're just syntax sugar around interfaces, so they should be easy to implement. But I don't have enough experience with FPC sources to do everything right and not brake anything. And then I realized, that it would be great to have extendable syntax. Even whole language could be build from scratch around compile-time extendable syntax. I would call it MetaPascal.

I think quite a lot could be done by going back to a fairly austere ALGOL-like base, with a design dogma that under no circumstances should types be promoted implicitly. On top of that allow explicit definition of operators and functions, and have traits associated with types indicating which operations could be inherited by subtypes, which needed to be redefined and so on.

However I think a serious stumbling block is the behaviour when a stack frame is unwound on function exit. Modern languages assume at least that there is a hook here which e.g. allows dynamically-allocated local strings to be freed and any exception state to be unwound, but it complicates explicit exit/return handling (i.e. as distinct from simply falling out of the end of the function) and has the potential to be a resource hog if units can be precompiled separately. I suspect that precompilation also implicitly complicates template/generic handling, and it's interesting that Stallman once looked at a language (Pastel) which allowed parametric types but found that this required that the entire program's abstract syntax tree be held in memory which was out of the question for the microprocessor-based computers of the day.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #46 on: August 23, 2021, 01:15:31 pm »
All I need - is to replace this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TIterator = reference to function:Integer;
  3.  
  4. var
  5.   Iterator:TIterator;
  6.  
  7. function CreateIterator:TClosure;
  8.   var I:Integer;
  9. begin
  10.   I := 0;
  11.   Result := function:Integer
  12.   begin
  13.     Result := I;
  14.     Inc(I);
  15.   end;
  16. end;
  17.  
  18. Iterator := CreateIterator;
  19.  
  20. WriteLn(Iterator);
  21.  
with this:
Code: Pascal  [Select][+][-]
  1. type
  2.   IIteratorInterface = interface;
  3.  
  4.   TIteratorMethod1 = function(Self:IIteratorInterface):Integer;
  5.  
  6.   IIteratorInterface = interface
  7.     function IteratorMethod1:Integer;
  8.   end;
  9.  
  10.   TIterator = record
  11.     Method:TIteratorMethod1;
  12.     Interface:IIteratorInterface;
  13.   end;
  14.  
  15.   TIteratorClass = Class(TInterfacedObject, IIteratorInterface)
  16.     I:Integer;
  17.     function IteratorMethod1:Integer;
  18.   end;
  19.  
  20. var
  21.   Iterator:TIterator;
  22.  
  23. function TIteratorClass.IteratorMethod1:Integer;
  24. begin
  25.   Result := I;
  26.   Inc(I);
  27. end;
  28.  
  29. function CreateIterator:TIterator;
  30.   var IteratorVar:TIteratorClass;
  31. begin
  32.    IteratorVar := TIteratorClass.Create;
  33.    IteratorVar.I := 0;
  34.    Result.Method := @IteratorVar.IteratorMethod1;//I know, it's wrong
  35.    Result.Interface := IteratorVar;
  36. end;
  37.  
  38. Iterator := CreateIterator;
  39.  
  40. WriteLn(Iterator.Method(Iterator.Interface));
  41.  
Now I need to learn how to change FPC sources for this. It would take too much time, would be too hard and counter-productive. But what if I would be able to add some Closures.pas unit to my project, where I would be able to describe closure extended syntax? It would be compiled to some sort of compiler runtime module, that would be able to handle closures at compile time.
« Last Edit: August 23, 2021, 01:26:47 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11384
  • FPC developer.
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #47 on: August 23, 2021, 02:26:44 pm »
FPC does not implement anonymous methods yet.  It has been in the works for years by 3rd party devels, but somehow it doesn't get finished (or submitted)

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #48 on: August 23, 2021, 03:38:03 pm »
FPC does not implement anonymous methods yet. It has been in the works for years by 3rd party devels, but somehow it doesn't get finished (or submitted)
May be that's because they think, that it's hard to implement? It's just another way of defining classes, that doesn't require class definition itself and therefore saves many code lines. Overall whole closure structure is something like this:
Code: Pascal  [Select][+][-]
  1. function ClosureContext:TClosureContainer;//Container - in case we want to have several closures
  2.   var <SomeOtherVariables>, <ClosureVariables>;
  3. begin
  4.   Result.Closure1 := <Closure1>;
  5.   Result.Closure2 := <Closure2>;
  6.   Result.Closure3 := <Closure3>;
  7. end;
  8.  
Turns into:
Code: Pascal  [Select][+][-]
  1. IClosureInterface = interface
  2.   <Closure1>
  3.   <Closure2>
  4.   <Closure3>  
  5. end;
  6.  
  7. TClassImlementingClosures = class(TInterfacedObject, IClosureInterface)
  8.   <ClosureVariables>
  9.   <Closure1>
  10.   <Closure2>
  11.   <Closure3>
  12. end;
  13.  
So, it's just matter of turning one code into another code. That's why having extendable syntax would be great for this task.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11384
  • FPC developer.
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #49 on: August 23, 2021, 04:01:07 pm »
FPC does not implement anonymous methods yet. It has been in the works for years by 3rd party devels, but somehow it doesn't get finished (or submitted)
May be that's because they think, that it's hard to implement? It's just another way of defining classes, that doesn't require class definition itself

It is primarily added for Delphi compatibility and there it is primarily used to schedule tasks in other threads.  But yes, it must dynamically capture state. (though that is horribly wonky in Delphi too, as it often captures references to state rather than the state itself). And it must all be memory safe in the end (though that builds on top of existing interfaces infra).

Why it takes so long I don't know, and since there is little info to base speculation on.

Quote
So, it's just matter of turning one code into another code. That's why having extendable syntax would be great for this task.

The syntax is already fixed by Delphi

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #50 on: August 23, 2021, 05:20:24 pm »
All I need - is to replace this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TIterator = reference to function:Integer;
  3.  
  4. var
  5.   Iterator:TIterator;
  6.  
  7. function CreateIterator:TClosure;
  8.   var I:Integer;
  9. begin
  10.   I := 0;
  11.   Result := function:Integer
  12.   begin
  13.     Result := I;
  14.     Inc(I);
  15.   end;
  16. end;
  17.  
  18. Iterator := CreateIterator;
  19.  
  20. WriteLn(Iterator);
  21.  
with this:
Code: Pascal  [Select][+][-]
  1. type
  2.   IIteratorInterface = interface;
  3.  
  4.   TIteratorMethod1 = function(Self:IIteratorInterface):Integer;
  5.  
  6.   IIteratorInterface = interface
  7.     function IteratorMethod1:Integer;
  8.   end;
  9.  
  10.   TIterator = record
  11.     Method:TIteratorMethod1;
  12.     Interface:IIteratorInterface;
  13.   end;
  14.  
  15.   TIteratorClass = Class(TInterfacedObject, IIteratorInterface)
  16.     I:Integer;
  17.     function IteratorMethod1:Integer;
  18.   end;
  19.  
  20. var
  21.   Iterator:TIterator;
  22.  
  23. function TIteratorClass.IteratorMethod1:Integer;
  24. begin
  25.   Result := I;
  26.   Inc(I);
  27. end;
  28.  
  29. function CreateIterator:TIterator;
  30.   var IteratorVar:TIteratorClass;
  31. begin
  32.    IteratorVar := TIteratorClass.Create;
  33.    IteratorVar.I := 0;
  34.    Result.Method := @IteratorVar.IteratorMethod1;//I know, it's wrong
  35.    Result.Interface := IteratorVar;
  36. end;
  37.  
  38. Iterator := CreateIterator;
  39.  
  40. WriteLn(Iterator.Method(Iterator.Interface));
  41.  
Now I need to learn how to change FPC sources for this. It would take too much time, would be too hard and counter-productive. But what if I would be able to add some Closures.pas unit to my project, where I would be able to describe closure extended syntax? It would be compiled to some sort of compiler runtime module, that would be able to handle closures at compile time.

Точнее, вы делаете больше работы, для того чтоб сделать больше работы в дальнейшем? Я смотрю на второй код, и вижу что он больше. Как при создании, так и при использовании.
В чём преимущество второго кода?

google translate:
More specifically, are you doing more work to do more work in the future? I look at the second code and see that it is larger. Both in creation and in use.
What is the advantage of the second code?
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #51 on: August 23, 2021, 05:24:04 pm »
It is primarily added for Delphi compatibility and there it is primarily used to schedule tasks in other threads.  But yes, it must dynamically capture state. (though that is horribly wonky in Delphi too, as it often captures references to state rather than the state itself). And it must all be memory safe in the end (though that builds on top of existing interfaces infra).

Why it takes so long I don't know, and since there is little info to base speculation on.
They're usable in any callbacks, that require state passing. While classes are data with code attached to them, closures are opposite - they're code with data attached to them. Test cases are implemented via closures in my project. There are thousands of them. It has taken many months to write this code. That's why their code should be kept as minimum, as possible. Rewriting this code using classes/interfaces would be massive job. But overall my goal is to fully migrate to Linux and get rid of Windows/Delphi dependency. I would want to help with it, but starting to dig into FPC sources from scratch - is too big thing for me and I really think, that it would be counter-productive.

Example of using closures in my project:
Code: Pascal  [Select][+][-]
  1. procedure AddTests(ATestCase:TObjectContainerTestCase<TAbstractList<Integer>, TArray<Integer>>;ASorted:Boolean);
  2.   var TestHelper:TAbstractTestHelper;
  3. begin
  4.   TestHelper := ATestCase.TestHelper;
  5.   with TestHelper do begin
  6. ...
  7.     ATestCase.AddTestCase(
  8.       'Query test',
  9.       True,
  10.       function(var ASource:TAbstractList<Integer>):TAbstractList<Integer>
  11.       begin
  12.         Result := ASource.Query(TDelegatedPredicate<Integer>.Create(
  13.           function(AValue:Integer):Boolean
  14.           begin
  15.             Result := AValue mod 2 = 0;
  16.           end
  17.         ));
  18.       end,
  19.       ArrayOfInteger([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
  20.       ArrayOfInteger([2, 4, 6, 8, 10])
  21.     );
  22. ...
  23.   end;
  24. end;
  25.  
Not 100% good example, because it doesn't show, that TestHelper methods or ASorted can be used inside callbacks, therefore it doesn't show all pros of using closures. One can argue, that above code can be implemented via static procedures.
« Last Edit: August 23, 2021, 05:43:19 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5448
  • Compiler Developer
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #52 on: August 26, 2021, 03:03:05 pm »
Why it takes so long I don't know, and since there is little info to base speculation on.

The feature itself is feature-complete, the remaining part is reintegration into main and right now the provided code is essentially akin to a cancer. Before that is restructured I'm not going to integrate that.

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #53 on: August 26, 2021, 10:44:22 pm »
pure assembly  :D :D

Really any ALGOL 60 (68?) descendant would have the same speed potential. It would only be a compiler matter. C, Pascal, Ada, teoretically can achieve same speed.
In certain (broad) way, C<->Pascal translation is nearly automatic.
And even i would say that pascal should do even better speed because compiler has more information (strong typed, and things like that).
On the other hand, it's difficult today thinking in a big app made with only one languaje. OS (platform) are in Cs* and even same compiler with same languaje (even C) could perform different from one OS to another...

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #54 on: August 27, 2021, 08:25:13 am »
Really any ALGOL 60 (68?) descendant would have the same speed potential. It would only be a compiler matter. C, Pascal, Ada, teoretically can achieve same speed.

I'm sorry, I disagree. As a specific example, a language which relies heavily on termination code at the end of every block to unwind temporary allocations and exception handlers will always be slower than one that doesn't provide that facility, and that is generally made worse if separate compilation prevents that from being optimised away (due to callbacks expecting the same stack layout).

Apart from that, just about everything is derived from ALGOL these days. Classic FORTRAN and COBOL have (thankfully) withered as have environments such as Lisp, Prolog, Smalltalk and Forth, and their descendants are quick to point out how much they've borrowed from ALGOL/Pascal/Ada: control blocks, data structures and the rest. But some of those descendants couldn't be implemented without heavy use of either reference counting or garbage collection, and again those are inherent time-wasters.

Quote
In certain (broad) way, C<->Pascal translation is nearly automatic.
And even i would say that pascal should do even better speed because compiler has more information (strong typed, and things like that).
On the other hand, it's difficult today thinking in a big app made with only one languaje. OS (platform) are in Cs* and even same compiler with same languaje (even C) could perform different from one OS to another...

I've had people in the past trying to convince me that UNIX-based systems could /only/ be programmed in C.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #55 on: August 27, 2021, 11:02:43 am »
Quote
'm sorry, I disagree. As a specific example, a language which relies heavily on termination code at the end of every block to unwind temporary allocations and exception handlers will always be slower than one that doesn't provide that facility, and that is generally made worse if separate compilation prevents that from being optimised away (due to callbacks expecting the same stack layout).

Apart from that, just about everything is derived from ALGOL these days. Classic FORTRAN and COBOL have (thankfully) withered as have environments such as Lisp, Prolog, Smalltalk and Forth, and their descendants are quick to point out how much they've borrowed from ALGOL/Pascal/Ada: control blocks, data structures and the rest. But some of those descendants couldn't be implemented without heavy use of either reference counting or garbage collection, and again those are inherent time-wasters.

Well, nothing to say, your point is valid, i agree. I was thinking more on c/pascal/ada tree of algol68.

Quote
I've had people in the past trying to convince me that UNIX-based systems could /only/ be programmed in C.

I've thinking a lot of times that i would love that history will make pascal - again- used as OS languaje. Any knows if there is being tried a OS coded in pascal or something like that?. It would be funny repeating the story of Linus Torvalds redoing kernel in FreePascal.
Sometimes i have thought (but i have no time) of making a mini OS made only in pascal as a start point for doing something bigger. Dreams...



MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #56 on: August 27, 2021, 11:10:32 am »
Well, nothing to say, your point is valid, i agree. I was thinking more on c/pascal/ada tree of algol68.

But FPC does have arbitrary unwind code at the end of functions and procedures, which is how locally-defined strings and dynamic arrays are freed.

Quote
I've thinking a lot of times that i would love that history will make pascal - again- used as OS languaje. Any knows if there is being tried a OS coded in pascal or something like that?. It would be funny repeating the story of Linus Torvalds redoing kernel in FreePascal.
Sometimes i have thought (but i have no time) of making a mini OS made only in pascal as a start point for doing something bigger. Dreams...

Yes, there've been many: as a specific example, Cray's OSes were coded in Pascal (although the anti-Pascal purists would attempt to save face by saying that because it was enhanced beyond the standard definitions it wasn't really Pascal). I've used Modula-2 for a microkernel plus network etc. BUT robust type checking becomes a problem as soon as you're passing variable-sized packets around which negates a lot of Pascal's advantage.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #57 on: August 27, 2021, 11:38:59 am »
Quote
Yes, there've been many: as a specific example, Cray's OSes were coded in Pascal (although the anti-Pascal purists would attempt to save face by saying that because it was enhanced beyond the standard definitions it wasn't really Pascal). I've used Modula-2 for a microkernel plus network etc.

I would search for these (itches my curiosity). Are there modern ones?.

Quote
BUT robust type checking becomes a problem as soon as you're passing variable-sized packets around which negates a lot of Pascal's advantage.
I don't know why. Even in the worst case one can take these as raw data, have fun with pointers and then process that like a C code. Well, i'm talking lightly without seeing the real problem. In worst scenario one will be like C and a nice reading code :)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #58 on: August 27, 2021, 11:48:54 am »
Quote
Yes, there've been many: as a specific example, Cray's OSes were coded in Pascal (although the anti-Pascal purists would attempt to save face by saying that because it was enhanced beyond the standard definitions it wasn't really Pascal). I've used Modula-2 for a microkernel plus network etc.

I would search for these (itches my curiosity). Are there modern ones?.

Most of the Cray engineering documentation and sources was destroyed: SGI had a beach bonfire party when they bought them. People like Chris Fenton have had some success scraping stuff together from old disk packs. As far as modern work is concerned, the thing that springs to mind is Oberon. There's also a modern Pascal-based stand-alone project for the Raspberry Pi although the name escapes me and I don't know how heavily it relies on assembler.

Unfortunately, most people these days think that "writing an operating system in XXXX" means yet another GUI built on top of Windows or Linux.

Quote
Quote
BUT robust type checking becomes a problem as soon as you're passing variable-sized packets around which negates a lot of Pascal's advantage.
I don't know why. Even in the worst case one can take these as raw data, have fun with pointers and then process that like a C code. Well, i'm talking lightly without seeing the real problem. In worst scenario one will be like C and a nice reading code :)

But the last thing you want if considering a robust language is to be passing pointers around without the compiler having the opportunity to check and enforce the size of the associated data... which is exactly what you get with stream-based protocols like TCP.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

damieiro

  • Full Member
  • ***
  • Posts: 200
Re: What is the FASTEST Computer Language? 45 Languages Tested!
« Reply #59 on: August 27, 2021, 02:49:50 pm »
Thanks MarkMLI

I will see the http://www.projectoberon.com/home  i allways love read Wirth

Quote
But the last thing you want if considering a robust language is to be passing pointers around without the compiler having the opportunity to check and enforce the size of the associated data... which is exactly what you get with stream-based protocols like TCP.
Yes, but i do not know a robust solution for this. Only say that FreePascal con do with same or better readibility than C and same performance. Designing a new protocol in...3..2..1..  >:D

 

TinyPortal © 2005-2018