Posts: 17293
Threads: 130
Joined: July 10, 2013
Reputation:
65
RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 6:47 am
FA - asks for help
Various knowledgeable members - offer help
FA - no that's not the answer I want
wash, rinse, repeat
I'm your huckleberry.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 6:48 am
(August 12, 2022 at 4:37 pm)HappySkeptic Wrote: (August 12, 2022 at 1:41 pm)FlatAssembler Wrote: Whence am I supposed to know all those things? I am just a third-year computer science student. And I have also been using a hell lots of things we haven't been taught at the university in my program.
A performance test is just a test program. It could be part of a unit-test. Just have it do something in a loop 1000 times (or some large-enough number). In Javascript
Code: var start = performance.now();
const iterations = 1000;
for (let i = 0; i < iterations; i++) {
// Do some testing work
}
var stop = performance.now();
console.log("Test 1 runs in " + ((stop - start)/iterations) + " ms.");
You said your program is "slow". How do you know? You must have expectations. At least this way you can check if something is slow or not, and find out if you fixed it or not, by comparing these numbers.
If something is slow, do a bunch of work in the loop, and do performance timing using the F12 developer console Performance tab in Chrome. You can start the recording from some "pause" point in your code, or you can start it with a page reload, and stop it when your code has finished. Look for the bottom-up methods, and check for calls that use a majority of the time.
Yeah. I have done some unit tests in the AEC-to-WebAssembly compiler, but I made no unit tests in the PicoBlaze Simulator, nor would I know how exactly to do those there.
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 6:55 am
(August 12, 2022 at 3:16 pm)BrianSoddingBoru4 Wrote: (August 12, 2022 at 1:41 pm)FlatAssembler Wrote: Whence am I supposed to know all those things? I am just a third-year computer science student. And I have also been using a hell lots of things we haven't been taught at the university in my program.
If you’ve been at this for three years and don’t understand performance tests, maybe you should enroll in a different CS programme.
Boru
Well, in Osijek, there are two universities teaching Computer Science, the FERIT university (the one I am attending) and the MATHOS university, and the FERIT university is considered much more prestigious.
Posts: 17293
Threads: 130
Joined: July 10, 2013
Reputation:
65
RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 6:57 am
(August 15, 2022 at 6:55 am)FlatAssembler Wrote: (August 12, 2022 at 3:16 pm)BrianSoddingBoru4 Wrote: If you’ve been at this for three years and don’t understand performance tests, maybe you should enroll in a different CS programme.
Boru
Well, in Osijek, there are two universities teaching Computer Science, the FERIT university (the one I am attending) and the MATHOS university, and the FERIT university is considered much more prestigious.
The school is doing a dandy job of educating you if you feel the need to go to an atheist forum, as well as other social media platforms for help.
I'm your huckleberry.
Posts: 9147
Threads: 83
Joined: May 22, 2013
Reputation:
45
RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 9:35 am
(This post was last modified: August 15, 2022 at 9:39 am by bennyboy.)
(August 15, 2022 at 6:44 am)FlatAssembler Wrote: Thank you, it would be a good thing to speed up the assembler a bit. But the assembler is, at least for the test programs, already running at an acceptable speed. It is the simulator that is running way too slowly. Well, at least this file was commented, so it's slightly more readable. It still seems to me that so many if/else statements is likely to cause trouble-- though if you're only running programs limited to 4KB, it's hard to believe that even an inefficient algorithm would take more than a split second.
Anyway, instead of so many repeated conditionals, I'd recommend using a large "switch":
Code: var codebyte = currentDirective & 0xff000;
switch (codebyte){
case 0x00000:
//Call a Register load from register function here.
break;
case 0x01000:
//Call a Register load from value function here.
break;
}
It's (much) better to generate a lookup table on compile than to keep constantly doing new comparisons. (I'm not so sure how much this will actually affect processing a small amount of data though).
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: PicoBlaze Simulator in JavaScript
August 16, 2022 at 12:37 pm
(August 15, 2022 at 6:57 am)arewethereyet Wrote: (August 15, 2022 at 6:55 am)FlatAssembler Wrote: Well, in Osijek, there are two universities teaching Computer Science, the FERIT university (the one I am attending) and the MATHOS university, and the FERIT university is considered much more prestigious.
The school is doing a dandy job of educating you if you feel the need to go to an atheist forum, as well as other social media platforms for help. What does "dandy" mean?
Posts: 2020
Threads: 133
Joined: July 26, 2017
Reputation:
5
RE: PicoBlaze Simulator in JavaScript
August 16, 2022 at 12:38 pm
(August 15, 2022 at 9:35 am)bennyboy Wrote: (August 15, 2022 at 6:44 am)FlatAssembler Wrote: Thank you, it would be a good thing to speed up the assembler a bit. But the assembler is, at least for the test programs, already running at an acceptable speed. It is the simulator that is running way too slowly. Well, at least this file was commented, so it's slightly more readable. It still seems to me that so many if/else statements is likely to cause trouble-- though if you're only running programs limited to 4KB, it's hard to believe that even an inefficient algorithm would take more than a split second.
Anyway, instead of so many repeated conditionals, I'd recommend using a large "switch":
Code: var codebyte = currentDirective & 0xff000;
switch (codebyte){
case 0x00000:
//Call a Register load from register function here.
break;
case 0x01000:
//Call a Register load from value function here.
break;
}
It's (much) better to generate a lookup table on compile than to keep constantly doing new comparisons. (I'm not so sure how much this will actually affect processing a small amount of data though).
I have always thought switch-case and large else-if statements compiled into the same assembly code.
Posts: 1692
Threads: 5
Joined: September 26, 2018
Reputation:
12
RE: PicoBlaze Simulator in JavaScript
August 16, 2022 at 1:23 pm
(August 16, 2022 at 12:38 pm)FlatAssembler Wrote: I have always thought switch-case and large else-if statements compiled into the same assembly code.
It depends on the language and how many items are in the switch statement.
Best case, the switch turns into a lookup table or map of jump instructions. Worst case they are the same. That makes switch the smart choice, as well as making the code more readable.
Posts: 9147
Threads: 83
Joined: May 22, 2013
Reputation:
45
RE: PicoBlaze Simulator in JavaScript
August 16, 2022 at 5:39 pm
(This post was last modified: August 16, 2022 at 6:14 pm by bennyboy.)
(August 16, 2022 at 12:38 pm)FlatAssembler Wrote: I have always thought switch-case and large else-if statements compiled into the same assembly code. That doesn't make sense. If you have a series of say 100 if/else statements, it is going to have to evaluate those one-by-one as part of the control flow of the app. But a switch statement can be evaluated as a single flow item. Look at your code-- how will you ever arrive at those items near the end of your long if/else chains? There's no way but for the CPU to go through all of those many evalutions one-by-one.
Now, I'm not an expert in computer languages. I can imagine that a very clever compiler will realize that all your conditional statements are being performed on the same object, and just generate a lookup table. But I'd be pretty surprised if that were the case with JavaScript running in a browser.
And EVEN IF they compiled the same (which I really do doubt), the appearance of code matters, too. A switch is easier to read.
Posts: 9915
Threads: 53
Joined: November 27, 2015
Reputation:
92
RE: PicoBlaze Simulator in JavaScript
August 16, 2022 at 7:24 pm
(November 14, 2020 at 3:35 pm)FlatAssembler Wrote: Can anybody here diagnose why the layout breaks in Firefox for Android when in the Landscape mode?
Why are you always asking us to do your homework for you?
Nay_Sayer: “Nothing is impossible if you dream big enough, or in this case, nothing is impossible if you use a barrel of KY Jelly and a miniature horse.”
Wiser words were never spoken.
|