简体   繁体   English

在我的网站上使用 Javascript 或 Python 进行计算会更好吗

[英]Would it be better to use Javascript or Python for calculations on my website

I am considering working on a project to emulate circuits in order to get more invested in an electronic circuits class that I am currently taking.我正在考虑开展一个模拟电路的项目,以便对我目前正在使用的电子电路 class 进行更多投资。 I have found it useful to create Python scripts to work on my homework calculations, but now I would like to make a website to share with classmates to use these scripts.我发现创建 Python 脚本来处理我的作业计算很有用,但现在我想创建一个网站与同学分享以使用这些脚本。

From my understanding, I can run only run Javascript on the browser and can only use Python on the backend.据我了解,我只能在浏览器上运行Javascript并且只能在后端使用Python I've gotten comfortable with using Python for math and have heard that it's better in general for mathematics.我已经习惯了使用Python进行数学运算,并且听说它通常更适合数学运算。 In my assignments, the most that I've worked with is pi and long floating point numbers.在我的作业中,我使用的最多的是pi和长浮点数。

So...所以...

Would it be worth my time to create a python backend to run calculations? 值得我花时间创建一个 python 后端来运行计算吗? Or can I get by with browser `Javascript` for calculations. 或者我可以使用浏览器“Javascript”进行计算。 I am comfortable with both languages. 我对这两种语言都很满意。

Also as a follow-up question, could I use Flask to run Python in the browser?另外作为后续问题,我可以使用Flask在浏览器中运行Python吗?

Thank you!谢谢!

The only case in which one would definitely be preferable to the other would be if the calculations to be performed may get very expensive, in which case it would be much more user-friendly to have the server shoulder the load, rather than having the client do it (since low-end clients may become unresponsive for too long while calculating).唯一一种肯定比另一种更可取的情况是,如果要执行的计算可能会变得非常昂贵,在这种情况下,让服务器承担负载而不是让客户端来对用户友好得多这样做(因为低端客户端在计算时可能会因为太长时间而变得无响应)。

If that's a potential issue for your case, running the expensive code on the backend would be the way to go.如果这对您的情况来说是一个潜在问题,那么在后端运行昂贵的代码将是 go 的方法。 (It doesn't have to be Python on the backend - it could even be server-side JS, or even PHP or whatever else you prefer and is performant enough for your needs.) (后端不必是 Python - 它甚至可以是服务器端 JS,甚至是 PHP 或其他任何您喜欢的,并且性能足以满足您的需求。)

If that isn't something to worry about for your case, then feel free to choose whatever you like (calculate on the client or on the server), using whatever approach you're most comfortable with - there isn't an objective way to choose between them.如果这不是您的情况需要担心的事情,那么请随意选择您喜欢的任何东西(在客户端或服务器上计算),使用您最熟悉的任何方法 - 没有客观的方法来在它们之间进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 javascript 或 php 进行计算? - Use javascript or php for calculations? JavaScript | 使用 Function 和 onclick ="",而不是 addEventListener("click",{}) 提高网站速度是否更好? - JavaScript | Is it better to use Function and onclick ="" , than addEventListener("click",{}) for website speed? 我如何使用JavaScript从其他网站检索文本? - How would I use JavaScript to retrieve text from a different website? 是否可以打开一个网站,然后使用 Python 在其中运行 JavaScript? - Would it be possible to open a website and then run JavaScript in it using Python? javascript toFixed 在我的计算中不起作用 - javascript toFixed not working in my calculations 我的 Javascript 计算未按计划进行 - My Javascript calculations are not working as planned 如何在我的网站(HTML、CSS 和 JavaScript)中使用来自 python 文件的数据? - How to use datas from a python file inside my website (HTML, CSS and JavaScript)? 计算列与JavaScript计算,哪个更好? - Computed columns vs. JavaScript calculations, Which is better? 如何改善JavaScript的结构以更好地利用OOP - How to improve the structure of my JavaScript to make better use of OOP 尝试使用forEach在我的数组中添加值-使用for循环会更好吗? - Trying to use forEach to add up values in my array - would I be better be using a for loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM