After working on the Project Euler problem #12, focusing on divisors and triangle numbers, I successfully solved it using both Go and JavaScript. Surprisingly, despite my assumption that the Go code would be much faster due to its building process compared to the runtime execution of JS, there were situations where the JS code outperformed the Go code.
Here is a snippet of the code I used:
https://gist.github.com/noraesae/675e40477e177f9f63f9
The test was conducted on my MacBook, which has the following specifications:
Processor: 2.6 GHz Intel Core i5
Memory: 8 GB 1600 MHz DDR3
I executed the code with the following commands:
$ #js
$ node euler12.js$ #go
$ go build euler12.go
$ ./euler12
I am puzzled by the fact that there was no significant difference in performance between the two languages. Could there be something wrong with my approach? If not, what could explain the lack of disparity in speed? Interestingly, when comparing Go to Python, there was a notable gap in performance. Any insights would be greatly appreciated. Thank you.