0

How can i get a very rough estimate of the runtime for simple mathematical algorithms written in mips assembly? Like factorial, Euclidean, Fibonacci? I've got my processors frequency and its 2.30 GHz, im on an MSI gaming laptop. I've read that the Intruction per cycle is usually between 1-2. The goal is to compare the runtimes of the same programs in java. In java it was pretty simple but mips assembly is a whole other story. I have read that assembly is generally faster than java(please confirm, assuming both are as optimized as they can be). Please note im no assembly pro whatsoever, im taking a computer architecture class and this is a project im doing.

I've tried checking out simulators like Mars and SPIM but they dont support this feature. I've done some research and noticed there are a lot of factors that come into play so im assuming thats why there arent any simulators that do this. Again i dont need an exact calculation, i could make up reasonable numbers that would make sense and plug them into a formula, any guidance would be appreciated.

  • 1
    Why not [edit] and follow up with your [existing post from yesterday](https://stackoverflow.com/q/76891544/6243352)? People responded to try to help you, basically the two best active MIPS answerers on the site. If nobody answered that, likely, nobody will answer this either, so making a new account and reposting it is counterproductive to your goal. Please only make one account. – ggorlen Aug 13 '23 at 23:35
  • Were you aware that [mips is dead](https://www.eejournal.com/article/wait-what-mips-becomes-risc-v/)? – Elliott Frisch Aug 13 '23 at 23:43
  • What has this question to do with Java? Apparently Java is just something that you mentioned in passing, not related to the subject matter. – aled Aug 13 '23 at 23:57
  • @ElliottFrisch, not my choice. Its a computer architecture class project that im working on. – Wajdy Elsobky Aug 14 '23 at 00:32
  • @aled, if you read again, i mention the goal is to compare the runtimes of java vs assembly. – Wajdy Elsobky Aug 14 '23 at 00:32
  • Test the same algorithm in both and derive an empirical formula based on the results. – aled Aug 14 '23 at 00:49
  • "I've tried checking out simulators like Mars and SPIM but they dont support this feature." What makes you say that those MIPS simulators don't support factorial, Euclidian, or Fibonacci? I think you have an incorrect perception that you need to get to the bottom of. – Erik Eidt Aug 14 '23 at 01:02
  • @ggorlen, the other account i created was on my phone and i didnt remember what email i used for this one. I've only used stack overflow liked 2 or 3 times and i Forgot i was already signed into this account my laptop. Anyway this is already posted so ill keep it up incase anyone else replies. I've responded on the other account. – Wajdy Elsobky Aug 14 '23 at 01:03
  • @ErikEidt, i meant they dont offer runtime calculations., figured it was clear since most of the post is about runtime and not the actual algorithms. – Wajdy Elsobky Aug 14 '23 at 01:05
  • @aled thats the thing, i need help manually calculating an approximate runtime for these assembly programs because there arent any simulators or resources that ive found online that do this for you. I need help coming up with reasonable values which i can plug into a formula to calculate it. Like cycles per instruction/ IPC, i think i understand how to estimate Instruction count but some resources have me second guessing and clock cycle time. – Wajdy Elsobky Aug 14 '23 at 01:10
  • *I have read that assembly is generally faster than java* - no, unless you're very good at writing assembly. See [Why does C++ code for testing the Collatz conjecture run faster than hand-written assembly?](https://stackoverflow.com/q/40354978) for an example of a beginner doing worse than even an un-optimized debug build. – Peter Cordes Aug 14 '23 at 01:47
  • *(please confirm, **assuming both are as optimized as they can be**)* - yes, in that hypothetical case, assembly is always at least as good as any other language, since you could just generate the same code the other language is using. (With dynamic optimization if necessary to beat it, like a JVM does when JIT compiling, treating runtime invariants as constants until/unless they change.) – Peter Cordes Aug 14 '23 at 01:48
  • But no, a simply-written program in assembly is often not faster than what a good modern compiler does, unless you're an expert. Especially for a superscalar in-order MIPS where you have to manually schedule instructions and unroll loops with software-pipelining to let them run in parallel and hide load latency and stuff like that. Surprisingly, modern out-of-order x86 CPUs are somewhat more forgiving for instruction ordering, but dependency chains still matter. If that didn't make sense to you, you have very little chance of making your program "as optimized as possible". – Peter Cordes Aug 14 '23 at 01:48
  • Anyway, if you were going to compare MIPS assembly running inside a simulator like MARS, SPIM, or QEMU, that will be *way* slower than a JVM running natively on your x86 CPU. To compete with that, you should be writing in x86 assembly. Benchmarking a MIPS simulator against an optimized JVM will just show you that a JVM's JIT compilation (of Java bytecode) to native x86-64 machine code performs way better than simple interpreters running on x86-64 treating MIPS machine code as data. – Peter Cordes Aug 14 '23 at 01:51
  • Most MIPS simulators probably aren't even aiming for really high performance. Maybe try a Nintendo64 emulator; it used a MIPS CPU, and game emulators have real-time performance requirements. But anyway, the CPU in your laptop isn't a MIPS CPU, so you can't talk about how MIPS assembly performs on **your** CPU without involving some software translation or emulation. You could talk about how it would perform on an actual MIPS CPU, but you'd have to pick one, and it will be vastly different from your modern x86-64. – Peter Cordes Aug 14 '23 at 01:52

0 Answers0