简体   繁体   English

为什么Java Processbuilder运行命令的速度比Python Subprocess慢4000倍

[英]why is Java Processbuilder 4000 times slower at running commands then Python Subprocess.check_output

I was trying to write a wrapper for a third party C tool using Java processbuilder. 我试图使用Java processbuilder为第三方C工具编写包装。 I need to run this process builder millions of times. 我需要运行此流程生成器数百万次。 But, I found something weird about the speed. 但是,我发现速度有些奇怪。

I already have a wrapper for this third party tool C tool for python. 我已经有一个用于python的第三方工具C工具的包装器。 In python, the wrapper uses the python subprocess.check_output. 在python中,包装器使用python subprocess.check_output。

So, I ran the java wrapper 10000 times with same command. 因此,我使用相同的命令运行了Java包装器10000次。 Also, ran the python wrapper 10000 time with same command. 另外,使用相同的命令运行python包装器10000次。

With python, my 10000 tests ran in about 0.01 second. 使用python,我的10000个测试在大约0.01秒内运行。

With java processbuilder, it ran in 40 seconds. 使用java processbuilder,它运行了40秒。

Can someone explain why I am getting large difference in speed between two languages? 有人可以解释为什么我在两种语言之间的速度差异越来越大吗?

You try this experiment with a simple command like "time". 您可以使用“ time”之类的简单命令尝试此实验。

It seems like python doesn't spawn subprocess. 看来python不会产生子进程。 Which is why it was faster. 这就是为什么它更快。

I am sorry with confusion. 对不起,我感到困惑。

thank you 谢谢

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM