String variables[] = new String[50000];
for( int i=0;i<variables.length;i++){
variables[i] = "s"+i;
}
// create String literals
long startTime0 = System.currentTimeMillis();
for(int i=0;i<variables.length;i++){
variables[i] = "hello";
}
long endTime0 = System.currentTimeMillis();
System.out.println("Time taken for creation of String literals : "
+ (endTime0 - startTime0) + " milli seconds" );
// create String objects using 'new' keyword
long startTime1 = System.currentTimeMillis();
for(int i=0;i<variables.length;i++){
variables[i] = new String("hello");
}
long endTime1 = System.currentTimeMillis();
System.out.println("Time taken for creation of String objects with 'new' key word : "
+ (endTime1 - startTime1)+" milli seconds");
long startTime2 = System.currentTimeMillis();
for(int i=0;i<variables.length;i++){
variables[i] = new String("hello");
variables[i] = variables[i].intern();
}
long endTime2 = System.currentTimeMillis();
System.out.println("Time taken for creation of String objects with intern(): "
+ (endTime2 - startTime2)+" milli seconds");
这段代码在文章中给出的结果为:
Time taken for creation of String literals : 0 milli seconds
Time taken for creation of String objects with 'new' key word : 160 milli seconds
Time taken for creation of String objects with intern(): 60 milli seconds
但是我在电脑上实际运行结果为:
Time taken for creation of String literals : 0 milli seconds
Time taken for creation of String objects with 'new' key word : 3 milli seconds
Time taken for creation of String objects with intern(): 7 milli seconds
刨除硬件运行速度差异,明显区别还是String.intern()执行到底有没有带来效率上的提高.似乎我的运行结果与作者要说明的事实恰恰相反.
分享到:
相关推荐
java performance2java performance2java performance2java performance2
Java 9 High Performance 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
When O’Reilly first approached me about writing a book on Java performance tuning, I was unsure. Java performance, I thought—aren’t we done with that? Yes, I still work on performance of Java (and ...
“The definitive master class in performance tuning Java applications…if you love all the gory details, this is the book for you.” –James Gosling, creator of the Java Programming Language ...
java performance4java performance4java performance4
Java® Performance Companion shows how to systematically and proactively improve Java performance with today’s advanced multicore hardware and complex operating system environments. The authors, who...
Java 9 High Performance 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或...
Java(TM) Performance and Scalability, Volume 1, provides invaluable advice that you will, no doubt, find useful in your coding. Presented in 48 concise lessons that target the most common and ...
Java EE 7 Performance Tuning and Optimization 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有...
Java® Performance Companion shows how to systematically and proactively improve Java performance with today’s advanced multicore hardware and complex operating system environments. The authors, who...
trouble shooting java performance 英文原版带书签。
high performance java persistence
The information in this book will help you write high−performance software for the Java platform. It presentsboth high−level strategies for incorporating performance tuning into your software ...
Java: High-Performance Apps with Java 9: Boost your application’s performance with the new features of Java 9 By 作者: Mayur Ramgir – Nick Samoylov ISBN-10 书号: 1789130514 ISBN-13 书号: ...
Title: Java EE 7 Performance Tuning and Optimization Author: Osama Oransa Length: 398 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-06-25 ISBN-10: 178217642X ...
Java Performance Companion 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或...
一本介绍java性能方面的书 非常适合高手进阶!
Java Performance Tuning pdf
Java Performance Tuning 版。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。