Freebasic v's C# code execution speed ?
Re: Freebasic v's C# code execution speed ?
My OP reads
Freebasic v's C# code execution speed ? ....does anyone here have C# installed ?
Id like to know how fast the for next loops are and other simple commands like Print "hello" or line (x,y)-(x,y) are by comparison
Can i assume from your replies that none of you have C# installed ?
if so fine, ill find someone who does have C# installed...or just reinstall it myself
this entire post ,could all have been over within 5 minutes
Freebasic v's C# code execution speed ? ....does anyone here have C# installed ?
Id like to know how fast the for next loops are and other simple commands like Print "hello" or line (x,y)-(x,y) are by comparison
Can i assume from your replies that none of you have C# installed ?
if so fine, ill find someone who does have C# installed...or just reinstall it myself
this entire post ,could all have been over within 5 minutes
Last edited by TESLACOIL on Jun 05, 2012 17:54, edited 1 time in total.
Re: Freebasic v's C# code execution speed ?
I have it installed, but just like you, I can't "be arsed" ;)
You could have installed it by now, by the way.
You could have installed it by now, by the way.
Re: Freebasic v's C# code execution speed ?
tell me about it ,lol
Ive got a bud who uses C# but i wont see him for a few weeks, we will write some speed tests then
wish i never asked (slaps forehead )
carry on all, as you where
Ive got a bud who uses C# but i wont see him for a few weeks, we will write some speed tests then
wish i never asked (slaps forehead )
carry on all, as you where
Re: Freebasic v's C# code execution speed ?
In case you really do want to do benchmarks, it is important to note that benchmarks are only applicable to algorithms, not compilers. You create multiple algorithms to complete the same task and benchmark those. Benchmarking how many times the CPU can increment a memory location is not a benchmark and can be calculated from the hardware documents anyway.
You really don't know what a benchmark is or what it is used for. Stress testing your ALU is not a benchmark.
You really don't know what a benchmark is or what it is used for. Stress testing your ALU is not a benchmark.
Re: Freebasic v's C# code execution speed ?
honestly, in robotics and game-making the bottlenecks eventually should be multi-threading time-spent-waiting, or lack of multithreading :P
it probably applies off the board, but as im making a game engine right now, i can tell that my mutex-lock stuff probably isnt optimal
i need to find a lock-free solution, or make some kind of simple queueing
it probably applies off the board, but as im making a game engine right now, i can tell that my mutex-lock stuff probably isnt optimal
i need to find a lock-free solution, or make some kind of simple queueing
Re: Freebasic v's C# code execution speed ?
I think that in recent times well-developed mainstream high-level languages/compilers generally do not have significant performance deficiencies. Your time would be much better spent benchmarking algorithms.TESLACOIL wrote:each command or code block will have a typical execution speed
if you want to test real world speed of a computer program written in a specific language this is one way to do it
each language will be more efficient in some respects than others, that's a given, even a simple for next loop can be very revealing as to the capabilities of the computer and the language that the for next loop is written in
dont underestimate the power of simple tests
more complex tests say on sorting, data , graphics manipulation will reveal wider trends, the simpler tests will pull up specific deficiencies
And if you do bother to compare loop times between FreeBASIC and C#, and it looks like the C# code is much faster, you need to look closer. To an optimizing compiler empty loops and other code where the results are not used are effectively “dead” code, so an obvious optimization is to remove them.
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
Re: Freebasic v's C# code execution speed ?
TESLACOIL:
Sounds like you want people to do work for you, then you get confused when they don't like how that feels. We're not a consultation forum. If you want a business/technology consultant, I cost about $xx an hour. If that's a problem for you, DIY.
"Simple speed test" - Since when were accurate benchmarks ever that simple?
You also talk like a manager/business guy, and I'm aware that you have expertise in certain areas. I'm also aware that a lot of that information is outdated or has been superceded by modern practices.
It'd just be nice if you were willing to listen to our feedback, rather than acting like we're being lazy, unmotivated, or worse, don't know what we're talking about. Appreciating us for our skill, you come here and ask questions. Full of hubris, you ignore what we say.
Sounds like you want people to do work for you, then you get confused when they don't like how that feels. We're not a consultation forum. If you want a business/technology consultant, I cost about $xx an hour. If that's a problem for you, DIY.
"Simple speed test" - Since when were accurate benchmarks ever that simple?
You also talk like a manager/business guy, and I'm aware that you have expertise in certain areas. I'm also aware that a lot of that information is outdated or has been superceded by modern practices.
It'd just be nice if you were willing to listen to our feedback, rather than acting like we're being lazy, unmotivated, or worse, don't know what we're talking about. Appreciating us for our skill, you come here and ask questions. Full of hubris, you ignore what we say.
Re: Freebasic v's C# code execution speed ?
I have a freebasic implementation of reader-writer locks. They are very fast non-blocking read locks and a invoke a mutual exclusion on write locks (many reader, one writer). I have also been working on a lockless queue for data synchronization, however it requires the CPU to support the cmpxchg8b instruction and is x86 only, but who isn't running at lease a P5 + extension or a P6 or higher? Since it relies on an instruction well established (almost 20 years now) that works atomically, (thus the worst-case is a retry on the update) it is much faster then any locking method (which all require high-level support (eg, mutexes)) and thus your miss on the update is measured in cycles (the amount of retries to be successful) and not in human measurable time slices.Gonzo wrote:...i can tell that my mutex-lock stuff probably isnt optimal
i need to find a lock-free solution, or make some kind of simple queueing
The rwlock code was ported from C, you can find it here. Although it is win32 only linux already natively supports many different concurrency controls including rwlocks.
Re: Freebasic v's C# code execution speed ?
There are many way to evaluate performance and in many times is irrelevant, but if you want real numbers is simple: find the problem you want to solve and see if your language of choice (I think FB) solves your problem in timely manner.
C# it should generate slower code overall but in a small margin, when compared against GCC backend in computational intensive codes. There is literature to compare C# with C/C++ and you will find like following numbers:
- in integer based codes C# is in the range of C/C++ (around 10-30% slower, sometimes is faster)
- in floating point matrix multiplication, C++ is some times faster if it match the autovectorizer optimization of the compiler
- in floating point when the compilers do not match any optimization they would work in the same range as integer based codes
- a lot of classes that are allocated on heap would run faster than C/C++. If you're using smart-pointers (reference counting) for C++ side) it would work even slower by many times than C#
- a lot of algorithms in the .Net framework library are well implemented and fairly fast(for reflection, xml processing, and so on) and if you are not looking to a good implementation on C++ side, or you make your own, you may find that your implementation may work slower than the C# side.
At the end, C# side is notoriously slow on startup as it has to decode the assemblies, to apply some optimization passes because of JIT step. This performance hit can be circumvented by using the right tool (NGen), but for a developer who is unaware, and not willing to optimize the startup time for a complex application, it may not be desirable to use C#. This hit of performance and the JIT time unpredictability can mean that some high complexity games may not be well intended for C# (at least if you don't have ways to pre-JIT your code), and can be a unsatisfactory experience.
At the end, if you are a beginner, I do recommend to you FreeBasic over C# not because of performance of either of them, but because you will have fewer things to know. C# is somewhat easy to start but hard to master, because of many technologies you should know to make an application working. Also C# used in a context like small games, would have a framework overhead which if you are not knowledgeable about PInvoke and other technology limitations, could mean that you will not be able to have your desired work.
A last small note: I'm a professional ex-C++ developer for 5 years, and another 3 in C# world. C# experience is gratifying, but my response is targeted for a beginner. I'm working with Ruby too, and even its performance is order of magnitude slower than both C# and C++, is good enough for a lot of usages. At the end I'm thinking that benchmarking is misleading in most of the ways, but people went well beyond it.
C# it should generate slower code overall but in a small margin, when compared against GCC backend in computational intensive codes. There is literature to compare C# with C/C++ and you will find like following numbers:
- in integer based codes C# is in the range of C/C++ (around 10-30% slower, sometimes is faster)
- in floating point matrix multiplication, C++ is some times faster if it match the autovectorizer optimization of the compiler
- in floating point when the compilers do not match any optimization they would work in the same range as integer based codes
- a lot of classes that are allocated on heap would run faster than C/C++. If you're using smart-pointers (reference counting) for C++ side) it would work even slower by many times than C#
- a lot of algorithms in the .Net framework library are well implemented and fairly fast(for reflection, xml processing, and so on) and if you are not looking to a good implementation on C++ side, or you make your own, you may find that your implementation may work slower than the C# side.
At the end, C# side is notoriously slow on startup as it has to decode the assemblies, to apply some optimization passes because of JIT step. This performance hit can be circumvented by using the right tool (NGen), but for a developer who is unaware, and not willing to optimize the startup time for a complex application, it may not be desirable to use C#. This hit of performance and the JIT time unpredictability can mean that some high complexity games may not be well intended for C# (at least if you don't have ways to pre-JIT your code), and can be a unsatisfactory experience.
At the end, if you are a beginner, I do recommend to you FreeBasic over C# not because of performance of either of them, but because you will have fewer things to know. C# is somewhat easy to start but hard to master, because of many technologies you should know to make an application working. Also C# used in a context like small games, would have a framework overhead which if you are not knowledgeable about PInvoke and other technology limitations, could mean that you will not be able to have your desired work.
A last small note: I'm a professional ex-C++ developer for 5 years, and another 3 in C# world. C# experience is gratifying, but my response is targeted for a beginner. I'm working with Ruby too, and even its performance is order of magnitude slower than both C# and C++, is good enough for a lot of usages. At the end I'm thinking that benchmarking is misleading in most of the ways, but people went well beyond it.
Re: Freebasic v's C# code execution speed ?
Which one on which architecture (VMs react differently to x86->x86_64 changes than statically compiled languages) ?TESLACOIL wrote:My OP reads
does anyone here have C# installed ?
Other border conditions?
What does that have to do with language? That just jumps directly to the system console output routine?Id like to know how fast the for next loops are and other simple commands like Print "hello"
Very dependent on canvas type.or line (x,y)-(x,y) are by comparison
Re: Freebasic v's C# code execution speed ?
Which in 9 out of 10 languages/platforms will lead to you to the same C run time library.marcov wrote:What does that have to do with language? That just jumps directly to the system console output routine?TESLACOIL wrote: Id like to know how fast the for next loops are and other simple commands like Print "hello"
Re: Freebasic v's C# code execution speed ?
I think that is a Unix centric generalization that is not so ubiquitous as many people think.codeFoil wrote:marcov wrote: Which in 9 out of 10 languages/platforms will lead to you to the same C run time library.
This is easily demonstrated by the fact that the global majority platform (windows) has not one but multiple C run time libraries, and usage of it is not part of the documented OS API, but part of the C/C++ development system (most 3rd party development systems that are not unix ports directly work with kernel32/user32, not with MSVCRT, if only because the msvcrt version of your choosing might not be installed in a few years. msvcrt not being a part of the portable (from win95 to windows 8) win32 api).
And even on Unix, it depends on what code you generate. If you generate a printf statement to write a simple string, you jump into a routine, but if you optimize it to emit a write() it might directly do the kernel call, but that skips buffering.
Last edited by marcov on Jun 09, 2012 19:45, edited 2 times in total.
Re: Freebasic v's C# code execution speed ?
lol , not being lazy....i just have a thang about running the numbers...though not everyone will be as geeky about real world benchmarks as i am
when i hook up with my fellow geek bencher in RL ill get some side by side FB vs C# code written
we do lots of ' how fast is it really ? tests ' all the time.....and yes wiggling yer mouse like crazy can chew up to 5% of cpu cycles
its a drag racing gene , car boats, motorbikes, computers.....if its got a speed dial im watching it lol
Its also partly related to my AI project and the choice of languages available to recode certain modules. Some parts of the network have a lot more CPU headroom than others and it would be nice to farm off some of the smaller modules that need recoding. I have RL links with some C & C# coders so i may bung them a crate of beer or three. Not so easy to communicate over the net or send payments. Exchanging folding stuff over a cool beer works well for me....partially explains my keen interest in the minutia of all things FreeBASIC / performance wise
*the complexity of the AI system is in the HW & SW architecture....so using FreeBASIC to develop the software eases brain strain for me. Yes ideally i need uber code speed but high readability has to take precedence....but its good to know the lines running through the ball park ref unoptimized but readable code vs optimized code and the ballpark losses or gain with a given language. * some of the modules are specific keyword heavy, so comparative performance is nice to know from my perspective. I can then configure the auto-coders to output in a specific language if there are significant speed or readability gains to be had.
as AMD has dropped out of the speed race its Intel's x86 et al architecture that will do the heavy lifting on the HW side , one less issue i have to worry about, though the next few installment of M$ windblows prolly wont see Santa's sack filled with thank you messages from me, lol
when i hook up with my fellow geek bencher in RL ill get some side by side FB vs C# code written
we do lots of ' how fast is it really ? tests ' all the time.....and yes wiggling yer mouse like crazy can chew up to 5% of cpu cycles
its a drag racing gene , car boats, motorbikes, computers.....if its got a speed dial im watching it lol
Its also partly related to my AI project and the choice of languages available to recode certain modules. Some parts of the network have a lot more CPU headroom than others and it would be nice to farm off some of the smaller modules that need recoding. I have RL links with some C & C# coders so i may bung them a crate of beer or three. Not so easy to communicate over the net or send payments. Exchanging folding stuff over a cool beer works well for me....partially explains my keen interest in the minutia of all things FreeBASIC / performance wise
*the complexity of the AI system is in the HW & SW architecture....so using FreeBASIC to develop the software eases brain strain for me. Yes ideally i need uber code speed but high readability has to take precedence....but its good to know the lines running through the ball park ref unoptimized but readable code vs optimized code and the ballpark losses or gain with a given language. * some of the modules are specific keyword heavy, so comparative performance is nice to know from my perspective. I can then configure the auto-coders to output in a specific language if there are significant speed or readability gains to be had.
as AMD has dropped out of the speed race its Intel's x86 et al architecture that will do the heavy lifting on the HW side , one less issue i have to worry about, though the next few installment of M$ windblows prolly wont see Santa's sack filled with thank you messages from me, lol
Re: Freebasic v's C# code execution speed ?
I have zero interest in C#, so I’m not willing to download and install it and then figure out how to do a meaningful comparison to FreeBASIC, assuming that it’s even reasonably possible. But I can easily do a comparison between code optimized (with /O2 /G6) by the Microsoft C compiler and code compiled with FBC, in this case between almost-empty for loops. The loops are almost-empty to avoid having the C compiler “optimize” the loop by removing it.
The C macros are available here:
http://masm32.com/board/index.php?topic=261.0
And the FreeBASIC macros (COUNTER.BAS) are here:
http://www.freebasic.net/forum/viewtopi ... =7&t=20003
The C code:
And the FreeBASIC code:
Typical results for the FreeBASIC code compiled with 0.23.0 with -arch set to the default 486, 686, or pentium3, running on a P3:
Typical results for the FreeBASIC code compiled with 0.23.0 with -arch set to the default 486, or pentium4, running on a P4 (Northwood):
Typical results for the C code running on a P3:
And typical results for the C code running on a P4 (Northwood):
I think it would be more meaningful to time other code, for example the popcount code that I used to test the new cycle count macros.
The C macros are available here:
http://masm32.com/board/index.php?topic=261.0
And the FreeBASIC macros (COUNTER.BAS) are here:
http://www.freebasic.net/forum/viewtopi ... =7&t=20003
The C code:
Code: Select all
//=======================================================================================
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include "counter_c.c"
//=======================================================================================
void main( void )
{
int i,j,x=0;
SetProcessAffinityMask( GetCurrentProcess(), 1);
Sleep(5000);
for( i=0; i < 4 ; i++)
{
counter_begin( 1, 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL );
counter_end( 1 )
printf("%d cycles\n", counter_cycles );
counter_begin( 2, 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL );
for( j=0; j < 10; j++)
x += 1;
counter_end( 2 )
printf("%d cycles\n\n", counter_cycles );
Sleep(1000);
}
printf("%d\n", x );
getch();
}
Code: Select all
''=============================================================================
#include "counter.bas"
''=============================================================================
dim as integer r, x
sleep 5000
SetProcessAffinityMask( GetCurrentProcess(), 1)
for i as integer = 1 to 4
counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
counter_end()
print counter_cycles;" cycles"
counter_begin( 10000000, REALTIME_PRIORITY_CLASS, THREAD_PRIORITY_TIME_CRITICAL )
for i as integer = 0 to 9
x += 1
next
counter_end()
print counter_cycles;" cycles"
print
sleep 1000
next
print x
sleep
Code: Select all
0 cycles
55 cycles
0 cycles
55 cycles
0 cycles
55 cycles
0 cycles
56 cycles
400000000
Code: Select all
0 cycles
67 cycles
0 cycles
67 cycles
0 cycles
68 cycles
0 cycles
69 cycles
400000000
Code: Select all
0 cycles
76 cycles
0 cycles
76 cycles
0 cycles
76 cycles
0 cycles
76 cycles
400000000
Code: Select all
0 cycles
37 cycles
1 cycles
40 cycles
0 cycles
43 cycles
1 cycles
38 cycles
400000000
Last edited by MichaelW on Jun 10, 2012 9:26, edited 1 time in total.
Re: Freebasic v's C# code execution speed ?
could you post up the code for counter.bas
i have a large variety of machines i can run your code on , from Atom to i5 2500k
Benchmarks & utilities
http://asimov1.wikispaces.com/Download+Benchmarks
Fritzbench will give you a feel for the general speed of a particular computer. Speedtest7.exe yields a similar results spread to Fritz when Fritz is set to one core
you might find the CPUID code here useful
http://en.wikipedia.org/wiki/CPUID
i have a large variety of machines i can run your code on , from Atom to i5 2500k
Benchmarks & utilities
http://asimov1.wikispaces.com/Download+Benchmarks
Fritzbench will give you a feel for the general speed of a particular computer. Speedtest7.exe yields a similar results spread to Fritz when Fritz is set to one core
you might find the CPUID code here useful
http://en.wikipedia.org/wiki/CPUID