This journey between programming languages is teaching me quite a bit, and, at the risk of getting all jargon-y about things, I'm fascinated with the computational efficiency of some forms of code, and the power of some processors I know how to work with.
Today's work, getting code laid down in the known programming language was actually quite successful, I coded well over 450 lines of pure assembly code. Those of you who know, or know of assembly, will ask "why the *expletive* is he using Assembly, rather than some nice high-level code like Java or C!!?" My answer has two parts: 1)because I'm slightly masochistic, and 2)because it's super efficient (each assembly statement requires around 50ns to compute. For comparison, the high-level languages require 1 millisecond to perform a single statement.)
This means my code is running around 20000 times faster when I punish myself by coding in assembly rather than the more familiar high-level language.
Tomorrow's work will be to finish a few (hundred) more lines of code that will actually control the audio interface to bring meaningful information to and from the chip and allow for volume control. Once that is complete, I'll begin the somewhat tedious task of transcribing my assembly code to C code, and maybe have an alpha version of the code to actually get a system running *fingers crossed* for a preliminary test. After that, who knows where I'll take the project. Maybe I'll add a super-pretty interface and bluetooth and wings. Who knows?
'Till then,
Alex Davis
20,000x faster? You sure? A single statement in a high level language does quite a bit more than a single statement in assembly so it makes sense that a statement in c will take longer than a statement in assembly. I wouldn't argue about assembly being faster if you do it correctly, but have you actually tested to see how much faster it is?
ReplyDeletetypical instructions in assembly on the processor require 4 clock cycles to execute, and 80000000 clock cycles occur per second, for a total of around 20 million instructions per second per core at eight cores. High level instructions must be decoded in realtime, resulting in around 1000 clock cycles per high level instruction. The overall execution speed for high level is around 80 thousand instructions per second per core. Though, admittedly, I'm not sure what was in the water the day I was writing this, because my calculations now are coming up with around 250 times faster assembly than high-level.
ReplyDeleteThe fundamental difference is that the high level language isn't compiled into assembly, it's tokenized and interpreted as it runs, which slows things down quite a bit.
Ah ok... I don't know much about assembly...
ReplyDeleteAnother quick question: when you say "statement" for a high level language do you mean that
int x=3
is a statement or are you referring to all the low level instructions (or statements) that occur behind the scenes to initialize x to 3?
by "statement" I am referring to the overall command, such as x += 1 or such commands. Since variables are all predeclared within system memory, I believe there is no delay for variable initialization, because all variables that exist within the system exist by default at runtime within the chip.
ReplyDelete