ページ

2014年4月1日

あれからJavaのリフレクションのスピードはどうなったのか?

僕が一番最近Javaのリフレクションのパフォーマンスを計測したのは、今のアリエルの開発を始めたぐらいで、ライブラリの選定をしている時でした。jdkのバージョンも覚えていません。それより前はいつやったのか覚えていません。
その時の結果の詳細は残っていませんが、リフレクションは通常のアクセスより10倍以上遅い、って印象だけが残っています。印象でものを語るのは良くないし、バージョンが上がるに連れて改善されているのかもしれないので、もう一度計測してみました。

以前は自分でコードを書いていたのですが、今回はサボって http://www.ibm.com/developerworks/jp/java/library/j-dyn0603/ にあるコードで試します。このページには1.4での計測結果ものっていて、いいかも。

ちなみに、今回はLinux上のSunのJDKでコンパイル・ビルド・実行しています。それから、結果に乗っている最初の一回目の数値は無視してください。

まず、リフレクションでオブジェクトを作るときの結果です。

Java version 1.7.0_51
Java HotSpot(TM) 64-Bit Server VM
24.51-b03
Oracle Corporation

Direct Object creation:
 49 1 2 1 2
 average time = 2 ms.
Reflection Object creation:
 44 3 3 2 3
 average time = 3 ms.
Direct byte[8] creation:
 10 7 8 11 10
 average time = 9 ms.
Reflection byte[8] creation:
 12 8 8 8 8
 average time = 8 ms.
Direct byte[64] creation:
 101 79 37 8 7
 average time = 33 ms.
Reflection byte[64] creation:
 7 7 7 8 8
 average time = 8 ms.

Direct Object creation:
 2 2 1 3 1
 average time = 2 ms.
Reflection Object creation:
 2 4 5 4 4
 average time = 4 ms.
Direct byte[8] creation:
 9 6 7 8 8
 average time = 7 ms.
Reflection byte[8] creation:
 8 8 10 9 8
 average time = 9 ms.
Direct byte[64] creation:
 9 8 11 9 7
 average time = 9 ms.
Reflection byte[64] creation:
 9 11 11 10 8
 average time = 10 ms.

オブジェクトの作成は若干リフレクションの方が遅いですが、使用用途にもよりますが、この程度であればリフレクションを使ってもそれほどオーバーヘッドもなく、問題ないでしょう。


次にオブジェクトの中のフィールドへのアクセスです。昔、偉い人が「privateなんて飾りです。リフレクションをシラン人はわからんのです。」って言っていましたが、それがこういうことです。
で、結果ですが、


Java version 1.7.0_51
Java HotSpot(TM) 64-Bit Server VM
24.51-b03
Oracle Corporation

Direct access using member field:
 8 6 6 7 6
 average time = 6 ms.
Reference access to member field:
 28 7 7 5 7
 average time = 7 ms.
Reflection access to member field:
 3544 3486 3437 3433 3482
 average time = 3460 ms.

Direct access using member field:
 7 5 7 6 6
 average time = 6 ms.
Reference access to member field:
 6 6 6 6 6
 average time = 6 ms.
Reflection access to member field:
 3538 3555 3515 3545 3482
 average time = 3524 ms.

で、reference accessはまあ、どうでもいいです。reflection accessだと、10倍どころじゃないですね。600倍ぐらい遅いです。数回だけならまだしも、アクセス数が増えると使い物にならないですね。JRubyとかJPythonは、基本的にメンバー変数に直接アクセスはしないんだろうか?

最後にメソッドの呼び出しです。

Java version 1.7.0_51
Java HotSpot(TM) 64-Bit Server VM
24.51-b03
Oracle Corporation

Direct call using member field:
 8 7 6 6 3
 average time = 6 ms.
Direct call using passed value:
 11 6 3 6 7
 average time = 6 ms.
Call to object using member field:
 10 6 7 7 6
 average time = 7 ms.
Call to object using passed value:
 8 6 5 7 6
 average time = 6 ms.
Reflection call using member field:
 71 32 30 29 33
 average time = 31 ms.
Reflection call using passed value:
 158 139 138 122 117
 average time = 129 ms.

引数なしでの呼び出しは、通常の5倍遅いです。引数ありでは20倍の遅さです。メンバー変数へ直接アクセスすするよりは、メソッドを通してアクセスするほうが効率は良さそうですね。

IBMのサイトの結果と比べると…、IBMのサイトのグラフが対数になっていて、よくわかりません。多分、あんまり変わっていないです。

ということで、

- リフレクションでのオブジェクトの作成はオーバーヘッドがほとんどない
- メンバーフィールドにアクセスするのは遅すぎるのでやらないほうがいい。
- メソッド呼び出しは5から20倍遅いので、使う場合は注意する

67 件のコメント:

for ict 99 さんのコメント...

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

sheela さんのコメント...

Excellant post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
Best Devops online Training
Online DevOps Certification Course - Gangboard

sasitamil さんのコメント...


It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Selenium training in bangalore

Ada Smith さんのコメント...

My favorite casino! purely top online casino I recommend to everyone!!! The engine does not slow down. I did not observe any breaks in the connection. Won $ 2200. Brought the winnings to no problem. Very beautiful, pleasant, comfortable casino. Very nice voice acting. Honesty control. In short .. all zashib

service care さんのコメント...

I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
redmi service center near me
mi service center

Unknown さんのコメント...

Click here to get daily info more.

Chris Hemsworth さんのコメント...

The article is so informative. This is more helpful. Thanks for sharing

Learn best software testing online certification course class in chennai with placement
Best selenium testing online course training in chennai
Best online software testing training course institute in chennai with placement
.

Madhu Balan さんのコメント...

All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
Java Training in Chennai
Java Training in Coimbatore
Java Training in Bangalore

chandhran さんのコメント...

I learned more information from this blog.the concepts are explained in detailed.
Aviation Academy in Chennai
Air Hostess Training in Chennai
Airport Management Courses in Chennai
Airport Ground Staff Training Courses in Chennai
Air hostess training in Bangalore
Aviation Academy in Chennai
Air Hostess Training in Chennai
Air Hostess Training in Chennai
Aviation Academy in Chennai
Aviation Courses in Bangalore

raneedevan さんのコメント...

nice blog..valuable information....thanks for sharing...
C C++ Training in Chennai
C Training in Chennai
C++ Training in Chennai
C C++ training in anna nagar
C C++ training in velachery
javascript training in chennai
core java training in chennai
Html5 Training in Chennai
DOT NET Training in Chennai
QTP Training in Chennai

shwethapriya さんのコメント...

Thanks for updating this information. Good job.
German Classes in Chennai
German Language Classes in Chennai
French Classes in Chennai
pearson vue test center in chennai
Informatica Training in Chennai
Data Analytics Courses in Chennai
German Classes in T Nagar
German Classes in Anna Nagar

yuvaprithika さんのコメント...

I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
Blue Prism Training in Chennai
Blue Prism Training
Azure Training in Chennai
Cloud Computing Training in Chennai
Automation Anywhere Training in Chennai
Blue Prism Training in Anna Nagar
Blue Prism Training in T Nagar
Blue Prism Training in OMR
Blue Prism Training in Porur

Aruna Ram さんのコメント...


Lovely post! This is a very fruitful post and I am impressed with the effort you have so obviously put into this content. Thanks for sharing.

Oracle Training in Chennai
best oracle training institute in chennai
Corporate Training in Chennai
Embedded System Course Chennai
Unix Training in Chennai
Pega Training in Chennai
Excel Training in Chennai
Soft SkillsTraining in Chennai
JMeter Training in Chennai
Oracle Training in Anna Nagar

navidevan さんのコメント...

Nice blog.....thanks for sharing...
core java training in chennai
core java training institutes in chennai
Best core java Training in Chennai
core java training in anna nagar
core java training in vadapalani
C C++ Training in Chennai
javascript training in chennai
Hibernate Training in Chennai
LoadRunner Training in Chennai
Mobile Testing Training in Chennai

Riya Raj さんのコメント...

The way you have conveyed your blog is more impressive.... good blog...
JAVA Training in Chennai
JAVA Course in Chennai
Java Training
Java classes in chennai
JAVA Training in Annanagar
java training in vadapalani
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
Selenium Training in Chennai

Sadhana Rathore さんのコメント...

I gathered lots of information from your blog and it helped me a lot. Keep posting more.
ccna course in Chennai
ccna Training in Chennai
ccna Training institute in Chennai
AngularJS Training in Chennai
Ethical Hacking course in Chennai
PHP Training in Chennai
CCNA course in Thiruvanmiyur
CCNA course in Porur
CCNA course in Adyar

sasi さんのコメント...

I really enjoyed this article. I need more information to learn so kindly update it.
DOT NET Training in anna nagar
DOT NET Training in Chennai
DOT NET Training in OMR
Software testing training in T Nagar
hadoop training in T Nagar
DOT NET Training in T nagar
SEO Training in OMR
Digital Marketing Course in anna nagar

Reshma さんのコメント...


Your post is really awesome .It is very helpful for me to develop my skills.
SEO Training in Velachery
SEO Training in T Nagar
SEO Training in Tambaram
SEO Training in Anna nagar
SEO Training in Porur
SEO Training in Thiruvanmiyur
SEO Training in Adyar
SEO Training in OMR
SEO Training in Vadapalani

Anbarasan14 さんのコメント...

Nice post. Thanks for sharing this post with us.
Spoken English Classes in Coimbatore
Best Spoken English Classes in Coimbatore
Spoken English Class in Coimbatore
Spoken English in Coimbatore
Spoken English Classes in Chennai
IELTS Coaching in Chennai
English Speaking Classes in Mumbai
IELTS Classes in Mumbai
Spoken English Class in Anna Nagar
IELTS Coaching in Tambaram

Patell Priya さんのコメント...

Nice Blog...Thanks for sharing the article waiting for the next update...
Artificial Intelligence Course in Chennai
best artificial intelligence training in chennai
C C++ Training in Chennai
javascript training in chennaiHtml5 Training in Chennai
QTP Training in Chennai
Spring Training in Chennai
DOT NET Training in Chennai
clinical sas training in chennai

Riya Raj さんのコメント...

Fantastic blog!!! Thanks for sharing with us, Waiting for your upcoming data.
Digital Marketing Course in Chennai
Digital Marketing Course
best digital marketing course in chennai
Digital Marketing Training in Chennai
Digital marketing course in vadapalani
Digital marketing course in porur
Python Training in Chennai
Hadoop Training in Chennai
Big data training in chennai
JAVA Training in Chennai

shivam さんのコメント...

Flying Shift - Packers & Movers in Bhopal

sridharraj さんのコメント...
このコメントは投稿者によって削除されました。
sridharraj さんのコメント...

Awesome Blog...Thanks for sharing, Waiting for next update...
Hibernate Training in Chennai
Spring Hibernate Training in Chennai
Spring and Hibernate Training in Chennai
hibernate training in anna nagar
hibernate training in vadapalani
Spring Training in Chennai
clinical sas training in chennai
DOT NET Training in Chennai
QTP Training in Chennai
LoadRunner Training in Chennai

divi さんのコメント...

awesome blog it's very nice and useful i got many more information it's really nice i like your blog styleweb design company in velachery

Prakash さんのコメント...

Awesome Blog!!! Thanks for it, it is more useful for us.
IOS Training in Chennai
ios training institute in chennai
Best ios Training institutes in Chennai
iOS Training
IOS Training in Annanagar
IOS training in vadapalani
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
JAVA Training in Chennai

virgoacp さんのコメント...

Aluminium Composite Panel or ACP Sheet is used for building exteriors, interior applications, and signage. They are durable, easy to maintain & cost-effective with different colour variants.

Adhuntt さんのコメント...

Great blog thanks for sharing. Are you looking for digital marketing service?
digital marketing company in chennai
seo service in chennai
web designing company in chennai
social media marketing company in chennai

Karuna さんのコメント...

Nice blog thanks for sharing Karuna Nursery is the Best Plant Nursery in Chennai.
plant nursery in chennai
rental plants in chennai
corporate gardening service in chennai

Pixies さんのコメント...

Excellent blog thanks for sharing Run your salon business successfully by tying up with the best beauty shop in Chennai - The Pixies Beauty Shop. With tons of prestigious brands to choose from, and amazing offers we’ll have you amazed.

Raj Sharma さんのコメント...


Awesome post. Good Post. I like your blog. You Post is very informative. Thanks for Sharing.

Core Java Training in Noida
.Net Training in Noida
Hadoop Training in Noida
Blockchain Training in Noida

Customer relationship management さんのコメント...

This is really an awesome post, thanks for it. Keep adding more information to this.selenium training in bangalore

Customer relationship management さんのコメント...

Really it was an awesome article,very interesting to read.You have provided an nice article,Thanks for sharing.coded ui training in bangalore

Customer relationship management さんのコメント...

Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving.big data testing training in bangalore

Customer relationship management さんのコメント...

Linking is very useful thing.you have really helped lots of people who visit blog and provide them use full information.mobile application testing training in bangalore

Customer relationship management さんのコメント...

Your articles really impressed for me,because of all information so nice.manual testing training in bangalore

Softgen Infotech さんのコメント...

Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective...

Softgen Infotech is the Best Oracle Training institute located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

Softgen Infotech さんのコメント...

Really i appreciate the effort you made to share the knowledge. The topic here i found was really effective...

Softgen Infotech is the Best Oracle Training institute located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

Softgen Infotech さんのコメント...

Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up…

Get Best SAP FICO Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.

Softgen Infotech さんのコメント...

Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

Get Best SAP MM Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.

eTechno Soft Solutions さんのコメント...

wonderful thanks for sharing an amazing idea. keep it...

Best SAP S4 HANA Training in Bangalore- eTechno Soft Solutions is a leading SAP S4 HANA Training Institute in Bangalore offering extensive SAP S4 HANA Training by Real-time Working Professionals along with 100% placement support, Booka Free Demo!

amit tavva さんのコメント...

keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

Extensiya さんのコメント...

Awesome blog thankks for sharing 100% virgin Remy Hair Extension in USA, importing from India. Premium and original human hair without joints and bondings. Available in Wigs, Frontal, Wavy, Closure, Bundle, Curly, straight and customized color hairstyles Extensions.

Indpac さんのコメント...

Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.

Reshma さんのコメント...

Such a great blog. I Got Lots of informations about this technology.Keep update like this....
Best IELTS Coaching in Bangalore
IELTS Training in Bangalore
IELTS Coaching centre in Chennai
IELTS Training in Chennai
IELTS Coaching in Bangalore
IELTS Coaching centre in coimbatore
IELTS Coaching in madurai
IELTS Coaching in Hyderabad
Selenium Training in Chennai
Ethical hacking course in bangalore

lokesh さんのコメント...

Keep sharing this blog. it look like very attractive content ....
PHP Training in Chennai
PHP Training in Bangalore
PHP Training in Coimbatore
PHP Course in Madurai
DevOps Training in Bangalore
DOT NET Training Institutes in Bangalore
PHP Training Institute in Chennai
PHP Training Institute in Bangalore
PHP Training Institute in Coimbatore
Best PHP Training Institute in Chennai

ek さんのコメント...

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
Please check this ExcelR Digital Marketing Courses in Pune

Mahi さんのコメント...

Our training institute is the best place to learn foreign languages. Enroll for the best German Language training center in Bangalore. Our Foreign Language School specialists in German language education. Join the best foreign language classes, training institute, coaching centers, tutors, instructors in Bangalore.

German Language Training in Bangalore

German Training Institute in Bangalore

German Institute in Bangalore

German Language Institute

Indian Institute of German & German Language

German Learning

German Language Institute in Bangalore

German Courses

German language course in Bangalore

learn German language in Bangalore

German language basics learning in Bangalore

learn German grammar in Bangalore

German learning centres contact addresses in Bangalore

German grammer tuition phone numbers in Bangalore

reviews of German language learning centres in Bangalore

ratings of German spoken classes in Bangalore

Mahi さんのコメント...

SAP ABAP Training in Bangalore with 100% placement. We are the Best SAP ABAP Training Institute in Bangalore. Our SAP ABAP courses are taught by working professionals who are experts in.

sap abap training in bangalore

sap abap courses in bangalore

sap abap classes in bangalore

sap abap training institute in bangalore

sap abap course syllabus

best sap abap training

sap abap training centers

Mahi さんのコメント...

Our training institute is the best place to learn foreign languages. Enroll for the best Italian Language training center in Bangalore. Our Foreign Language School specialises in Italian language education. Join the best foreign language classes, training institute, coaching centers, tutors, instructors in Bangalore.

Italian Language Training In Bangalore

Italian Training Institute in Bangalore

Italian Institute in Bangalore

Italian Language Institute

Indian Institute of Italian & Italian Language

Italian Learning

Italian Language Institute in Bangalore

Italian Courses

Italian language course in Bangalore

learn Italian language in Bangalore

Italian language basics learning in Bangalore

learn Italian grammar in Bangalore

Italian learning centres contact addresses in Bangalore

Italian grammer tuition phone numbers in Bangalore

reviews of Italian language learning centres in Bangalore

ratings of Italian spoken classes in Bangalore

Mahi さんのコメント...

Machine Learning Course in Bangalore with 100% placement. We are the Best Machine Learning Course Institute in Bangalore. Our Machine Learning course and Certification courses are taught by working professionals who are experts in Machine Learning .

Machine Learning Training in Bangalore

Machine Learning course in bangalore

Machine Learning in bangalore

Machine Learning classes in bangalore

Machine Learning course institute in bangalore

Machine Learning course and Certification course syllabus

best Machine Learning course

Machine Learning course centers

Navin Prakash さんのコメント...

It is a very helpful data. It will help to improve my knowledge about this topic. Thank you for this awesome post.
Corporate Training in Chennai
Corporate Training institute in Chennai
Spark Training Institute in Chennai
Social Media Marketing Courses in Chennai
Graphic Design Courses in Chennai
Oracle Training in Chennai
Appium Training in Chennai
Tableau Training in Chennai
Power BI Training in Chennai
Linux Training in Chennai
Corporate Training in OMR

dataexpert さんのコメント...

This was really one of my favorite website. Please keep on posting. ExcelR Digital Marketing Class In Pune

Kevin Davidson さんのコメント...

It's very useful blog post with inforamtive and insightful content and i had good experience with this information. We, at the CRS info solutions ,help candidates in acquiring certificates, master interview questions, and prepare brilliant resumes.Find top Salesforce admin interview questions in 2020.
These Salesforce developer interview questions are highly helpful in 2020. You can read these Salesforce lightning interview questions and Salesforce integration interview questions which are prepared by industry experts.

lavanya さんのコメント...


I am very happy when read this blog post because blog post written in good manner and write on good topic. Thanks for sharing valuable information about Digital Marketing Course.

Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

CloudLearn ERP さんのコメント...

You must have a lot of pride in writing quality content. I'm impressed with the amount of solid information you have written in your article. I hope to read more.
Best Data Science training in Mumbai

Data Science training in Mumbai

Janu さんのコメント...

I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.



Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery










saran さんのコメント...

Really nice post. Thank you for sharing amazing information.
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

Anu さんのコメント...

Nice Article! I learn more important information from your post. It was really interesting and useful post. I like more updates to your blog...
DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery

Anirban Ghosh さんのコメント...

You must have a lot of pride in writing quality content. I'm impressed with the amount of solid information you have written in your article. I hope to read more.
SAP training in Kolkata
SAP training Kolkata
Best SAP training in Kolkata
SAP course in Kolkata
SAP training institute Kolkata

Data Science Institute In Banglore さんのコメント...

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
Data Science Institute in Bangalore

subha さんのコメント...


Thank you very much for the help. I'm still in shock that this is the simplest way to distinguish clicks on a check box or an item. keep share more
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai

DataScience Datascience さんのコメント...

You re in point of fact a just right webmaster. The website loading speed is amazing. It kind of feels that you're doing any distinctive trick. Moreover, The contents are masterpiece. you have done a fantastic activity on this subject!
Data Science Course in Bangalore

DataScience Datascience さんのコメント...

Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!
Data Science Training in Bangalore

Customer relationship management さんのコメント...

I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.

SAP HR Online Training

SAP HR Classes Online

SAP HR Training Online

Online SAP HR Course

SAP HR Course Online

Customer relationship management さんのコメント...

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.

SAP SD Online Training

SAP SD Classes Online

SAP SD Training Online

Online SAP SD Course

SAP SD Course Online

Customer relationship management さんのコメント...

Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

sap hana training in bangalore

sap hana class in bangalore

learn sap hana in bangalore

places to learn sap hana in bangalore

sap hana schools in bangalore

sap hana school reviews in bangalore

sap hana training reviews in bangalore

sap hana training in bangalore

sap hana institutes in bangalore

sap hana trainers in bangalore

learning sap hana in bangalore

where to learn sap hana in bangalore

best places to learn sap hana in bangalore

top places to learn sap hana in bangalore

sap hana training in bangalore india