Programming Languages Benchmark

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming Languages Benchmark

Post by dodicat »

Srvaldez
Here is the gsl mat mult.
Just printing the first few.
need to rename the dll's to suit the .bi files.

Code: Select all

'' Matrix example
'#include "gsl/gsl_matrix.bi"
#include "gsl/gsl_blas.bi"

'' gsl uses the c-style row major order, unlike VB or Fortran
? "A 1024 X 1024 matrix"
Dim As gsl_matrix Ptr m = gsl_matrix_alloc(1024, 1024)
Dim As gsl_matrix Ptr ANS = gsl_matrix_alloc(1024, 1024)
For i As Integer = 0 To 1023
    For j As Integer = 0 To 1023
        gsl_matrix_set (m, i, j, rnd)
    Next
next

For i As Integer = 0 To 2
    For j As Integer = 0 To 2
        Print "m(";i;",";j;") = "; gsl_matrix_get (m, i, j)
    Next
next
?
var t=timer
gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, m, m, 0.0,ANS)
'gsl_matrix_transpose(m)
print "Please wait . . ."
? "And its mult"
For i As Integer = 0 To 4
    For j As Integer = 0 To 4
          print gsl_matrix_get (ANS, i, j);" ";
        'Print "m(";i;",";j;") = "; gsl_matrix_get (m, i, j);" "
    Next
    print
next
print timer-t;" seconds"

Sleep
'gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, AT, A, 0.0, ATA);
 

Code: Select all

A 1024 X 1024 matrix
m( 0, 0) =  0.3300995409954339
m( 0, 1) =  0.3290384791325778
m( 0, 2) =  0.5324827746953815
m( 1, 0) =  0.8565621743910015
m( 1, 1) =  0.6610786700621247
m( 1, 2) =  0.7479131908621639
m( 2, 0) =  0.8974834950640798
m( 2, 1) =  0.8981972737237811
m( 2, 2) =  0.5467735875863582

Please wait . . .
And its mult
 262.6486463557366  264.133080690532  249.9497284622075  245.8091856571758  254.4816434351048
 263.3985818790719  260.8396857922957  260.8670042773451  249.3802523355828  258.5021913291369
 268.9591884238063  271.5696752277466  258.6585253350781  258.5611465891471  261.974347618632
 265.0566194185634  276.0721704942844  263.1457048062646  252.8500506755962  261.9810002295936
 259.1286359025576  261.340898823149  252.9454020572635  250.7773381067099  253.602059421662
 1.554729300085455 seconds
 
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Programming Languages Benchmark

Post by srvaldez »

not bad dodicat
but why in the world do this blas libraries have such cryptic function names?
and not only cryptic names but cryptic calling methods :x
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming Languages Benchmark

Post by dodicat »

I suppose once you do a task once (say solving linear equations) then you have a template.
Most external libraries look a bit cryptic, probably because freebasic syntax is so easy, and fb users get spoiled.
IMHO anyways.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Programming Languages Benchmark

Post by srvaldez »

hello dodicat, all
would you have a look at the CLblast archive? https://drive.google.com/file/d/1aEVPQc ... sp=sharing
its from https://github.com/CNugteren/CLBlast
fbfrog translated the clblast_netlib_c.h with no problems and I tried to translate sgemm_netlib.c and while the translated code compiles and runs with no complaints I am not confident that it's working as it should, I added this loop right after printf(!"Completed SGEMM\n")

Code: Select all

	i=0
	while i<m*n
		? host_c[i]
		i+=1
	wend
but all it prints is -35829.23
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Programming Languages Benchmark

Post by caseih »

This has been an interesting exercise that drives home to me that if you were trying to ascertain the fitness of a particular language for a specific purpose one needs to really benchmark that particular task as it is normally done in that language, rather than just transliterating the same procedural algorithm into each language. Certainly the OP's benchmark shows that tight for-loops doing sequential math is very slow on Python and obviously faster in a compiled language. My pure python version shows that using Python idioms such as lists and generators can be quite fast, many times faster than simple loops. However really if the task was to multiply large matrices, we have shown that when using the proper tools, the language itself doesn't actually matter at all. Python, FB, C, Java are all the same speed. In that case just use the language you are comfortable with, and whatever language makes all the rest of your task easier, such reading in the data to be multiplied, creating the user interface, etc. This is why Matlab was so popular and why Python is becoming popular in these big data fields.

For FB users, FB is clearly a good choice for matrix multiplication once you make a few wrapper functions to hide the interface to GSL and BLAS.

I commend the OP for writing code in so many languages. It's always fun.
Vinion
Posts: 19
Joined: Sep 08, 2022 6:27

Re: Programming Languages Benchmark

Post by Vinion »

Hello everyone!

With this benchmark I am not comparing programming language features or how clever a developer can be. I am comparing how fast a programming language can do a for loop, the most basic loop in the history of programming, and add data to an array.

The best solution to the problem my benchmark describes is linear algebra.
The second best is Java's parallel streams.
And the third is numpy which implements a pure linear algebra solution.

Perhaps the Python's C = matrix_mul(A,B) is much faster than 3 "For Loops" or even better solution is numpy but you cannot use matrix_mul and numpy all the time.

For example on a stockmarket webservice reading data from a client, multiplying 2 values included in the data with a 3rd value included in the service and sending them back. These multiplications are independent and cannot be done with matrix_mul(). In this case the same server software written in Python would take 4426 seconds/processor core to serve its clients while a server written in FreeBasic would take just 25.8seconds/processor core and I am not even going to add Java to this battle.

Python is a horrible programming language. It has a horrible syntax and it is horribly slow. On the other hand BASIC(FreeBasic) has the most humane syntax and it is 170times faster than the snake...
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming Languages Benchmark

Post by dodicat »

srvaldez wrote: Sep 14, 2022 4:04 hello dodicat, all
would you have a look at the CLblast archive? https://drive.google.com/file/d/1aEVPQc ... sp=sharing
its from https://github.com/CNugteren/CLBlast
fbfrog translated the clblast_netlib_c.h with no problems and I tried to translate sgemm_netlib.c and while the translated code compiles and runs with no complaints I am not confident that it's working as it should, I added this loop right after printf(!"Completed SGEMM\n")

Code: Select all

	i=0
	while i<m*n
		? host_c[i]
		i+=1
	wend
but all it prints is -35829.23
I downloaded and tried sgemm_netlib.bas
However the program is looking for opencl.dll, which I don't have.
The only thing I notice is
dim host_a as single ptr = cptr(single ptr, malloc((sizeof(single) * m) * k))
dim host_b as single ptr = cptr(single ptr, malloc((sizeof(single) * n) * k))
dim host_c as single ptr = cptr(single ptr, malloc((sizeof(single) * m) * n))
Your c uses n(64) and not k(512) like the others.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Programming Languages Benchmark

Post by srvaldez »

dodicat
you can get the dll from https://github.com/KhronosGroup/OpenCL- ... 2022.05.18
and the dll.a plus the bi and examples by D.J.Peters from viewtopic.php?p=217135#p217135
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Programming Languages Benchmark

Post by caseih »

Few programmers in other languages (python included) will ever switch to FB despite your toy benchmarks or your opinion of the language's syntax. I don't think you will ever quite understand the reasons. But that's completely okay. FB is a wonderful language and project, no doubt about it. Pretty amazing for a small group of volunteers.
Vinion wrote: Sep 14, 2022 6:30With this benchmark I am not comparing programming language features or how clever a developer can be.
Well it turns out language features are what programmers take advantage of to be efficient and write code that performs well. So you'd be a fool to not take advantage of a language's features if you were selecting an appropriate language for a task!
I am comparing how fast a programming language can do a for loop, the most basic loop in the history of programming, and add data to an array.
Yes I figured you would say that. Indeed the overhead of an interpreted language at running a tight loop will be much greater. Did you also benchmark QBasic against FB? Turns out that benchmark tells you almost nothing about a language's performance in the real world. I think my pure python example illustrates that nicely, as well as the numpy results (numpy is always used by programmers who need fast math).
Python is a horrible programming language. It has a horrible syntax and it is horribly slow. On the other hand BASIC(FreeBasic) has the most humane syntax and it is 170times faster than the snake...
Yes you keep saying that but it doesn't make it true, certainly not for every task and for every person[1]. You have an opinion, just like we all do. That is all. Syntax is a matter of taste. For me Python is not "slow" at anything I've done with it and the syntax allows me to code at a rate that far exceeds what I've done in any other language---that's the primary reason Python is so popular. I've worked in many languages over the years including C, C++, Java, C#, Pascal, and also FB. But the cool thing is working in Python does not prevent me from also using compiled languages, even in the same project. That's one of the great things about python: other languages complement it nicely; it's a glue language. Python is way faster than FB at particular tasks, such as parsing and filtering text files (something data scientists do every day). Sometimes a Bash shell script is faster yet. All depends on the task. It's wonderful to have so many tools available at no cost. FB, GCC, Python, Bash, Perl, or even Go and Rust if you were inclined. Programming future never has been so bright.

My goal is not to convince you to use Python---in fact I recommend you avoid Python. Just use caution when presenting your opinions as universal facts. And take benchmarks with lots of salt.

[1] A language I regard as truly horrible is Javascript. However many, many people love Javascript and write amazing and blazing-fast things with it and totally love it and it's ugly syntax. Javascript is fast becoming the world's most widely-used language.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming Languages Benchmark

Post by dodicat »

You have only had 4 posts Vinion.
I mentioned in the other thread that freebasic used to have many members up for speed tests.
I thought those days were over, but apparently not.
The speed tests in this thread seem to be emanating from libraries.
But never mind, you are entitled to your opinion about Python.
But it was written in C anyway, so around and around we can go when a can of worms is opened.
What the boffins use is up to them, it is they who give us bull****.
There was a question this morning on the telly:
What does a black hole consist of
1) Space debris.
2) Hydrogen + helium.
3) Dead stars.
Seemingly Dead stars is the answer.
Now anybody tell me that how on Earth(or off it) , can any human being have knowledge of the innards of a black hole? (if there is such a thing)
And these are the Python boffins who are looking for aliens to zap.
I am all for science, yes, and I like Physics, but there is an Outer limit.
srvaldez.
I'll try that when I get back, I am going to take the dog for a walk in Torrs Warren forest.
Vinion
Posts: 19
Joined: Sep 08, 2022 6:27

Re: Programming Languages Benchmark

Post by Vinion »

Hello caseih,

Unfortunately I wrote a lot of Python so there is no possible way to convince me to write or to not.
Python is a programming language and programming languages are like tools. I use tools when I have to and I never make fun of them. I will never make fun of a Philips screw driver because it cannot unscrew a Din912 screw... See my point....

In the beginning I used Python to write scripts to render models using Poser3D for video games and later for almost all kind of things for gaming platform backends. Coming from C# and Java to the snake universe I soon realized that Python is not just horrible... it is horrible and full of Runtime surprises like any other interpreted language. Runtime surprises is what all devs needs to turn their day into a really busy day...

The other horrible thing of this interpreted language, like most interpreted languages, is that they made it to write code fast and fast means that it is a Dynamically-typed languages. Variables can change types on every CPU cycle making everything incredible flexible and vulnerable at the same time. This is the reason Python and other Dynamically-typed languages are not used for enterprise scaled applications.

But what about Facebook? Facebook is written in PHP and PHP is an interpreted Dynamically-typed language exactly like python ??
Yes. I already know that and I am sure that if they knew how big Facebook would be today, when they started writing it, they would probably choose an other solution like C# or Java.

As for the Syntax... If I gain access to your SVN/Git repository tonight I can change your whole software's logic if I delete 4-5 tab characters. This is something that cannot happen with BASIC BASIC, Java, C, C# and even Javascript. Yes.. A syntax that can be destroyed if I delete a tab is not just bad, it is horrible.

As for the glue language... I bet you are missing GraalVM (https://www.graalvm.org/) the polyglot Virtual Machine by Oracle. You can write Java, Python, Javascript, R, Ruby and run them using Java Virtual Machine. If you love python you will love it. You will feel the difference instantly.

For me, as I already said, Python is a tool. It is slow, dumb, fragile but if someone is paying me to use it then "Yes sir! I will write snake code for you!" but I will never use it for my personal projects.

To be fair I have to admin that Python brought programming to none programmers and this deserves a huge thumbs up.
Python is the BASIC language of our days and the BASIC language of the future.



caseih wrote: Sep 14, 2022 14:52 Few programmers in other languages (python included) will ever switch to FB despite your toy benchmarks or your opinion of the language's syntax. I don't think you will ever quite understand the reasons. But that's completely okay. FB is a wonderful language and project, no doubt about it. Pretty amazing for a small group of volunteers.
Vinion wrote: Sep 14, 2022 6:30With this benchmark I am not comparing programming language features or how clever a developer can be.
Well it turns out language features are what programmers take advantage of to be efficient and write code that performs well. So you'd be a fool to not take advantage of a language's features if you were selecting an appropriate language for a task!
I am comparing how fast a programming language can do a for loop, the most basic loop in the history of programming, and add data to an array.
Yes I figured you would say that. Indeed the overhead of an interpreted language at running a tight loop will be much greater. Did you also benchmark QBasic against FB? Turns out that benchmark tells you almost nothing about a language's performance in the real world. I think my pure python example illustrates that nicely, as well as the numpy results (numpy is always used by programmers who need fast math).
Python is a horrible programming language. It has a horrible syntax and it is horribly slow. On the other hand BASIC(FreeBasic) has the most humane syntax and it is 170times faster than the snake...
Yes you keep saying that but it doesn't make it true, certainly not for every task and for every person[1]. You have an opinion, just like we all do. That is all. Syntax is a matter of taste. For me Python is not "slow" at anything I've done with it and the syntax allows me to code at a rate that far exceeds what I've done in any other language---that's the primary reason Python is so popular. I've worked in many languages over the years including C, C++, Java, C#, Pascal, and also FB. But the cool thing is working in Python does not prevent me from also using compiled languages, even in the same project. That's one of the great things about python: other languages complement it nicely; it's a glue language. Python is way faster than FB at particular tasks, such as parsing and filtering text files (something data scientists do every day). Sometimes a Bash shell script is faster yet. All depends on the task. It's wonderful to have so many tools available at no cost. FB, GCC, Python, Bash, Perl, or even Go and Rust if you were inclined. Programming future never has been so bright.

My goal is not to convince you to use Python---in fact I recommend you avoid Python. Just use caution when presenting your opinions as universal facts. And take benchmarks with lots of salt.

[1] A language I regard as truly horrible is Javascript. However many, many people love Javascript and write amazing and blazing-fast things with it and totally love it and it's ugly syntax. Javascript is fast becoming the world's most widely-used language.
Vinion
Posts: 19
Joined: Sep 08, 2022 6:27

Re: Programming Languages Benchmark

Post by Vinion »

dodicat you don't sound like a dog's person...

You really do not know what a black hole consists of ? Really ??
Well.. It is a common knowledge that black holes consists of Python devs and their friends looking for 'that missing tab'

dodicat wrote: Sep 14, 2022 15:17 You have only had 4 posts Vinion.
I mentioned in the other thread that freebasic used to have many members up for speed tests.
I thought those days were over, but apparently not.
The speed tests in this thread seem to be emanating from libraries.
But never mind, you are entitled to your opinion about Python.
But it was written in C anyway, so around and around we can go when a can of worms is opened.
What the boffins use is up to them, it is they who give us bull****.
There was a question this morning on the telly:
What does a black hole consist of
1) Space debris.
2) Hydrogen + helium.
3) Dead stars.
Seemingly Dead stars is the answer.
Now anybody tell me that how on Earth(or off it) , can any human being have knowledge of the innards of a black hole? (if there is such a thing)
And these are the Python boffins who are looking for aliens to zap.
I am all for science, yes, and I like Physics, but there is an Outer limit.
srvaldez.
I'll try that when I get back, I am going to take the dog for a walk in Torrs Warren forest.
Vinion
Posts: 19
Joined: Sep 08, 2022 6:27

Re: Programming Languages Benchmark

Post by Vinion »

To all programming language lovers and haters

https://youtu.be/vcFBwt1nu2U
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Programming Languages Benchmark

Post by caseih »

What cause me to comment was not my ego, or your dislike of Python, but your attack on some very smart people (implying they were stupid) for their choice of tools in your very first post:
I heard many astrophysicists uses Python to write custom scripts and analyze data received from radio-telescopes and stuff. Perhaps Python's performance has to do with the fact that we have not find any alien civilizations yet... Analyzing data with Python would take years, while with Basic or some other language it would take a few days.
I'm sure you thought it was humorous, but in reality it is simply dishonest. If you lay down a strong opinion as if it were a fact, be prepared to accept criticism of your opinion and demonstrations as to why they are not facts. I've been very careful in what I said to be strictly truthful. I have not misrepresented Python's performance either, restating several times it is an interpreter, not a compiler, wjhich excels at certain kinds of problem solving, where it is exceptionally fast and extremely efficient. If that were not true astrophysicists would not be using it to analyze large amounts of data.

Nor have I tried to explicitly encourage anyone to abandon FB and try it. I'm not evangelizing Python here, despite it being invaluable to what I do.

Anyway, FB is indeed a wonderful tool (just another tool), and is under-appreciated, even unknown in the wider world, useful for many things. I'm grateful for srvaldez and dodicat for pointing me at GSL and with some working examples. Those are good tips and tricks to have in the toolbox.

Looking forward to reading a post from you on what you are using FB for, and how it's benefiting a project you are working on. Or some slick way of doing something in FB.
Vinion
Posts: 19
Joined: Sep 08, 2022 6:27

Re: Programming Languages Benchmark

Post by Vinion »

For the James Gosling shake... I'm not attacking anyone!

A tool will never define the worker's brain and skills. A tool is just a tool... The worker just needs to pick up the correct tool for his work.

I a currently working on a RAD framework for FB in which I will transfer things from Java.
The framework's name is Kiwi (https://github.com/nsiatras/kiwi/wiki --> See the wiki pages on the right menu)

I already implement File, ArrayList (see the code bellow) and I will implement more collections like Queue and HashMap. I will also add Threads, TCP & UDP sockets and Serial Connection and perhaps more things...

Kiwi's Typed ArrayList :)

Code: Select all

#include once "kiwi\lang\System.bi"
#include once "kiwi\util\ArrayList.bi"

' In this example we will create an ArrayList that holds Students
Type student
	firstName as String
	lastName As String
End Type

' Define a new ArrayList type that hold's student
DefineArrayList(student)

' Initialize a new ArrayList to hold students
Dim students As ArrayList_Student

Dim student1 As student
student1.firstName = "James"
student1.lastName = "Gosling "
students.Add(student1) ' Add student1 to students ArrayList

Dim student2 As student
student2.firstName = "Elon"
student2.lastName = "Musk"
students.Add(student2) ' Add student2 to students ArrayList

print "Students ArrayList contains " & students.size() & " elements"
print ""

print "Students: "
for i as Integer = 0 to students.size()-1
	print "Student " & i & " = " & students.get(i).firstName &" " & students.get(i).lastName 
next i
Post Reply