OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:26 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 7:26 am 
Offline

Joined: Thu Nov 20, 2014 4:06 pm
Posts: 23
Hi,

I was just wondering, for a particular application, lets say a HelloWorld, how faster is an assembly kernel in comparaison to Linux ?
Do you any link to any benchmark or just a rough idea of the speed ratio ?

Thanks for your replies,


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 7:30 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
In general, assembly is faster than most other programming languages and more compact as well. You have many examples. Compare KolibriOS and Linux, for example. KolibriOS is written entirely in assembly language.
This also applies for user mode programs; programs written in assembly language are usually faster than those written in C and other languages.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 7:52 am 
Offline
Member
Member

Joined: Sat Mar 15, 2014 3:49 pm
Posts: 96
No meaningful comparison can be made.

Overall OS performance is about features and how those features are implemented and how programs interact or contend for those features.

A cooperative multi-tasking operating system allows a program to decide when to task-switch so enables programs to hog the CPU and do more work between task switches, for example, but a file system without a cache will slow down that same program if its doing predictable IO. Swings and roundabouts.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 8:06 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

remy wrote:
I was just wondering, for a particular application, lets say a HelloWorld, how faster is an assembly kernel in comparaison to Linux ?
Do you any link to any benchmark or just a rough idea of the speed ratio ?


Note: It's hard not to be biased. You should know I've been programming in assembly for over 20 years, mostly writing OS related code (boot code, kernels, etc), and am currently writing the next version of my boot code and kernel in assembly.

The exact speedup from hand crafted assembly depends far too much on what the code actually does, how skilled the programmers is, how well a compiler would've optimised, what the target CPU/s are, etc. It can range from nothing to maybe 100% in extreme/rare cases (but on average it's generally more like 5%).

However, the problem with assembly is that the more you optimise the harder it is to maintain; and for most code most of the time maintenance is far more important than squeezing a trivial performance increase out of it. What this means is that (assuming a project is 100% assembly) a good assembly language programmer won't even try optimise most of the code and a compiler will beat a good assembly language programmer almost all of the time.

More often than not; people claiming that assembly is faster in practice are not doing a fair comparison. For example they'll compare something like Menuet (with very minimal features) to something like Linux (that supports a massive number of features). In this case you can expect the former to be faster because it has less features, not because it's written in assembly. This happens frequently, simply because it takes longer to write code in assembly and therefore you end up with less features in the same amount of time.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 8:27 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
remy wrote:
Hi,

I was just wondering, for a particular application, lets say a HelloWorld, how faster is an assembly kernel in comparaison to Linux ?
Do you any link to any benchmark or just a rough idea of the speed ratio ?

Thanks for your replies,

You have to compare like with like, i.e. an assembler-only kernel that does all that the Linux kernel does with Linux itself.

The assembler-only kernel will take far longer to execute, mainly because you have to factor in the time to actually develop such a kernel. This means that a simple program executing under the Linux kernel will take a few seconds at most. I'd guess it would be a few decades, at best, for an assembler-only kernel. (By that time, of course, the Linux kernel will have advanced further. ;))

It's a bit like asking "Which spacecraft will get to the moon first - Apollo 11 or a faster-than-light drive powered spacecraft?".


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 8:53 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
And again an assembly-vs-other-languages thread. Waiting for "real programmers" to rush in.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 9:22 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
Actually, is it the time needed for writing the actual code, i.e. implementing the design, the bottleneck at all? If you have a good design and you know what you are doing, you would get an impressive amount of features, code, everything, after a few years of coding your project in assembly. As always, it is not that simple. In practice, I agree that high-level languages are much more productive.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 9:32 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:59 am
Posts: 543
Location: Shahpur, Layyah, Pakistan
I used to think that assembly was faster than, say, C. But now I have realized that it matters little in new and fast microprocessor with advanced optimization and parallel execution techniques, and in new highly optimized compilers.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 10:24 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Antti wrote:
Actually, is it the time needed for writing the actual code, i.e. implementing the design, the bottleneck at all?

The proof of the pudding is in the eating. The simple fact is that no-one has produced a kernel written only in assembler that has a fraction of the capabilities of the Linux kernel, the FreeBSD kernel, the Windows kernel, .... And, let's face it, they never will.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 10:36 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
I believe implementing complex logics and algorithms with plain assembly draw programmer's focus, which could otherwise be used to pay more attention on the design itself.

How many of us can write quick sort in assembly that beat code generated by gcc? and with sane/usable interface?

Bottom line, assembly is cool in some situation, but use all the tools you know, which is not limited to assembly.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 12:08 pm 
Offline
Member
Member
User avatar

Joined: Sun Jan 13, 2013 6:24 pm
Posts: 90
Location: Grande Prairie AB
I think this question needs to be narrowed in scope. It is an inalienable fact that object code generated by any means is as fast as any other, the only potential assembled code has is to be more compact. As an example.
Code:
     push   ss
     pop   ds
   xor   eax, eax
   cpuid
   push   word 0
   push   ecx
   push   edx
   push   ebx
   mov   ax, sp
   
   push   word 3
   push   word 0x1720
   push   ax
   call   ShowS
This snipped extracts the 12 character processor ident, constructs an ASCIIZ string and displays it. Extrapolate upon this, it's not unreasonable to think code designed in assembly would be 1/2 the size of HLL.

I'm a vehement proponent of assembly and it is because of its simplicity. Therefore I can focus on the instruction set rather than linker scripts, compiler switches etc. However, if my mandate was beyond hobbyist, assembly wouldn't even be in contention. Inarguably, the fewer instructions, the faster the throughput.

I believe notwithstanding all other considerations and the simple answer to the question is, a well designed assembler kernel could be considerably faster than otherwise.


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 2:45 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
@TightCoderEx: Linker scripts are related to binary formats. It is no way related to languages. With assembly scripts can also be needed. And you don't need to bother with compiler switches, you can just set them once in your build script.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 4:11 pm 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
TightCoderEx wrote:
Inarguably, the fewer instructions, the faster the throughput.


Nope. That's not true at all; modern CPUs have very complex, non-obvious performance characteristics. Your hand-crafted assembly with the minimum possible number of instructions could very easily be slower than a longer, more complex set of instructions produced by a compiler.

For an incredibly simple example, consider that on x86 most CPUs, the "LOOP" instruction is slower than a "DEC, JNZ" pair. For a more complex example, consider that the fastest way to copy a large block of memory on a modern x86 CPU is with a fairly complex SSE-based algorithm; which outperforms the shortest possible algorithm by an order of magnitude.

These days, CPU performance is complex and equally complex modern compilers are often better at producing fast code than all but the very best assembly-language programmers. Not only that, but if the compiler is doing the optimisation, the higher level source code can be kept simpler and easier to maintain, unlike hand-written assembly. Also, if a new optimisation technique is discovered, updating a compiler to take advantage of it is far easier than re-writing assembly.

While writing optimised assembly can be a fun and rewarding exercise, and a great way of learning about the low-level operation of the CPU, in terms of real-world performance it's often harmful.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 10:43 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
omarrx024 wrote:
In general, assembly is faster than most other programming languages and more compact as well. You have many examples. Compare KolibriOS and Linux, for example. KolibriOS is written entirely in assembly language.
This also applies for user mode programs; programs written in assembly language are usually faster than those written in C and other languages.
I did compare KolibriOS disk cache and Linux disk cache. I'm not an expert at reading assembly but it seems that the KolibriOS disk cache uses a linear search for finding disk blocks. Linux uses a page cache that is integrated into its mmap facility. The page cache is indexed by red-black trees. I conclude that either KolibriOS has a tiny cache and will be 'slower' than Linux or that KolibriOS has a large cache and will be 'slower' than Linux.

Therefore assembly is slower.

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
 Post subject: Re: Speed : Assembly OS vs Linux
PostPosted: Sun May 17, 2015 11:12 pm 
Offline
Member
Member

Joined: Wed Oct 30, 2013 1:57 pm
Posts: 306
Location: Germany
That sort of a conclusion is dangerous, as you're comparing different algorithms in different languages. Even though the argument is somewhat flawed, your point is correct: hand-crafted assembly is often not better than one in a language like C, due to extremely simplified maintenance.

The only methods that I would do in assembly are the ones you have to do in assembly (LGDT/LIDT/LTR, ISRs etc.) + some libc functions, where optimizing can be extremely profitable (I'd say that for some functions a speedup by 100x is possible). For a correctly and thoroughly tested written libc function, maintenance shouldn't be a thing.

Talking about such a topic is relatively useless, as it is highly biased and heavily depends on the ability of the programmer to write/maintain assembly.

_________________
managarm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group