为什么我的应用程序在IntelliJ中比命令行运行得更快? [英] Why is my application running faster in IntelliJ compared to command-line?

查看:103
本文介绍了为什么我的应用程序在IntelliJ中比命令行运行得更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序通过拆分数据并对其进行排序来导入大量文件。运行JUnit测试用例时,整个过程大约需要 16分钟

We have an application that imports a large amount of files by splitting the data and sorting it. When running the JUnit test case, the whole process takes about 16 minutes.

相同测试,使用 mvn clean完成test -Dtest = MyTest 34分钟中运行。

Same test, done with mvn clean test -Dtest=MyTest run in 34 minutes.

我们正在调用 / bin / sort 来对文件进行排序。这种情况似乎需要更长的时间。我不明白有什么不同。

We are calling in to /bin/sort to sort the files. The sort seems to be taking longer. I don't understand what is different.

查看IntelliJ,它运行

Looking at IntelliJ it runs with

/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/Applications/IntelliJ IDEA 10.app/bin -Dfile.encoding=UTF-8 -classpath %classhpath% com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 xxx.IntTestImportProcess,testImportProcess

我在OS X上。所有类都是使用Spring注入的。有哪些可能的建议是关于IntelliJ中这种性能提升背后的理论?测试是相同的。我无法共享所有代码,因为有这么多。但我可以根据要求添加任何细节。

I am on OS X. All the classes are injected using Spring. What are some possible suggestions are theories at what is behind this performance gain in IntelliJ? The tests are identical. I can't share all of the code because there is just so much. But I can add any detail if requested.

这是我的主要课程,以及我如何运行这两个课程。

Here is my main class and how I am running both.

public static void main(String... args) throws IOException {
        if(args.length != 2) {
            System.out.println("Usage: \n  java -jar client.jar spring.xml data_file");
            System.exit(1);
        }
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext(args[0]);
        PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendMinutes()
                .appendSuffix("minute", "minutes")
                .appendSeparator(" and ")
                .appendSeconds()
                .appendSuffix("second", "seconds")
                .toFormatter();
        URI output = (URI) applicationContext.getBean("workingDirectory");
        File dir = new File(output);
        if(dir.exists()) {
            Files.deleteDirectoryContents(dir.getCanonicalFile());
        }
        else {
            dir.mkdirs();
        }
        ImportProcess importProcess = applicationContext.getBean(ImportProcess.class);
        long start = System.currentTimeMillis();
        File file = new File(args[1]);
        importProcess.beginImport(file);
        Period period = new Period(System.currentTimeMillis() - start); // in milliseconds
        System.out.println(formatter.print(period.toPeriod()));
    }

我决定删除JUnit并使用main()方法。结果完全一样。 IntelliJ又来了。这是疯狂的日志。

I have decided to remove JUnit and just use a main() method. The result are exactly the same. IntelliJ is again. Here is the crazy log.

使用IntelliJ

With IntelliJ

DEBUG [ main] 2011-08-18 13:05:16,259 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/usage]
DEBUG [ main] 2011-08-18 13:06:09,546 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/customer]

使用java -jar

With java -jar

DEBUG [ main] 2011-08-18 12:10:16,726 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/usage]
DEBUG [ main] 2011-08-18 12:15:55,893 [er.DelimitedTextUnixDataSorter] Sorting file [/Users/amirraminfar/Desktop/import-process/customer]

排序命令是

sort -t'    ' -f -k32,32f -k18,18f -k1,1n

如上所示,在Intellij中排序需要 1分钟,但在java -jar需要 5分钟

As you can see above, sorting in Intellij take 1 minutes but in java -jar takes 5 minutes!

更新

我使用 /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents运行了所有内容/ Home / bin / java 并且排序仍然需要超过5分钟。

I ran everything using /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/bin/java and the sorting still takes well over 5+ mins.

推荐答案

谢谢大家的帮助。事实证明,IntelliJ以 LANG = C 开始排序。 Mac OS X终端默认在 UTF8 中排序,这解释了性能损失。希望这个答案会对某人有所帮助。

Thank you everybody for helping. It turns out IntelliJ starts sort with LANG=C. Mac OS X terminal sorts by default in UTF8 which explains the performance loss. Hopefully this answer will help somebody.

这篇关于为什么我的应用程序在IntelliJ中比命令行运行得更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆