Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
#渋谷java : Java の数学関数を計算速度的に極めたい
Search
KOMIYA Atsushi
April 23, 2016
Programming
1.5k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
#渋谷java : Java の数学関数を計算速度的に極めたい
第十五回 #渋谷java
http://shibuya-java.connpass.com/event/29113/
での発表資料です。
KOMIYA Atsushi
April 23, 2016
More Decks by KOMIYA Atsushi
See All by KOMIYA Atsushi
#JJUG Java における乱数生成器とのつき合い方
komiya_atsushi
5
5.6k
#JJUG Fork/Join フレームワークを効率的に正しく使いたい
komiya_atsushi
0
610
[#JSUG] SmartNews における container friendly な Spring Boot アプリケーション開発
komiya_atsushi
1
11k
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
5.5k
#devsumi 自然言語処理・機械学習によるファクトチェック業務の支援
komiya_atsushi
1
4.9k
SmartNews Ads における機械学習の活用とその運用 #mlops
komiya_atsushi
3
21k
GBDT によるクリック率予測を高速化したい #オレシカナイト vol.4
komiya_atsushi
5
1.4k
Maven central repository の artifact をランキングする #渋谷java
komiya_atsushi
0
1.6k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.5k
Other Decks in Programming
See All in Programming
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
210
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
190
Simple Storage Service(S3) is not simple
iwatsukayura
0
330
気持ちぃ〜角丸 Squircle
ryu1013
0
340
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.3k
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
120
ActionController meets Protocol Buffers
sorah
1
710
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
200
残高管理から台帳サービスへの進化
artoy
1
210
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.7k
AmebaブログはKMPから卒業します
kmars0605
0
240
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
240
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
Abbi's Birthday
coloredviolet
4
10k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
490
Thoughts on Productivity
jonyablonski
76
5.4k
Test your architecture with Archunit
thirion
2
2.5k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
470
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Transcript
Java ͷֶؔΛ ܭࢉతʹۃΊ͍ͨ ौ୩ Java 15th, 2016-04-23 KOMIYA Atsushi
͓·͑ͩΕΑ
KOMIYA Atsushi @komiya_atsushi
None
Spark ຊΛॻ͖·ͨ͠ͷͰ ΑΖ͚͠Εͥͻ͝ߪೖ͍ͩ͘͞ʂ
ࠓͷτϐοΫ
Java ͷֶؔ
java.lang.Math ͔Β࢝Ίͯ Java ͷֶؔͷܭࢉΛ ٻ͍͖ͯ͠·͢
Implementations of Math functions in JDK
java.lang.Math & java.lang.StrictMath
JDK ඪ४ͷֶؔ • ֶؔͷ࣮ͱͯ͠ java.lang.Math ͱ java.lang.StrictMath ͕ఏڙ͞Ε͍ͯΔ • ͦΕͧΕԿ͕ҧ͏ͷ͔ʁ
java.lang.StrictMath • https://docs.oracle.com/javase/jp/8/docs/api/java/lang/ StrictMath.html ΑΓ • ʮJavaϓϩάϥϜͷҠ২ੑΛอͭͨΊʹɺ͜ͷύοέʔδʹ͋ΔҰ ෦ͷؔͷఆٛɺطଘͷΞϧΰϦζϜͱಉҰͷܭࢉ݁ՌΛग़ ͢͜ͱ͕ٻΊΒΕ͍ͯ·͢ɻ͜͏ͨ͠ΞϧΰϦζϜɺ༗໊ͳωο τϫʔΫɾϥΠϒϥϦͰ͋Δnetlib͔ΒʮFreely
Distributable Math Libraryʯ(fdlibm)ύοέʔδͱͯ͠ೖखՄೳͰ͢ɻ͜ΕΒͷΞϧΰ ϦζϜCݴޠͰهड़͞Ε͓ͯΓɺͯ͢ͷුಈখԋࢉ͕Java ͷුಈখԋࢉϧʔϧʹै࣮ͬͯߦ͞ΕΔͷͱݟͳ͞Ε· ͢ɻʯ
java.lang.StrictMath • ҟͳΔϓϥοτϑΥʔϜ (OS, CPU ͳͲ) ʹ ͓͍ͯɺϏοτύλʔϯͷϨϕϧͰಉ݁͡Ռ ͕ฦ͞ΕΔ͜ͱ (࠶ݱੑ)
͕อূ͞Ε͍ͯΔ • ੑೳೋͷ࣍
java.lang.Math • https://docs.oracle.com/javase/jp/8/docs/api/ java/lang/Math.html ΑΓ • ʮStrictMathΫϥεͷҰ෦ͷϝιουͱҟͳ ΓɺMathΫϥεͷՁؔͷͯ͢ͷ࣮ɺ ϏοτରϏοτͷಉ݁͡ՌΛฦ͢Α͏ʹఆٛ͞Ε ͍ͯ·ͤΜɻ͜ͷΏΔ͔͞ʹΑͬͯɺݫີͳ࠶ݱ
ੑ͕ཁٻ͞Εͳ͍࣮ʹ͓͍ͯύϑΥʔϚϯεͷ ্͕ՄೳʹͳΓ·͢ɻʯ
java.lang.Math • CPU ʹґଘ໋ͨ͠ྩͳͲར༻͠ͳ͕Βɺ ΑΓΑ͍ੑೳΛఏڙ͢Δ • ͨͩ͠ʮਖ਼֬͞ʯΛ٘ਜ਼ʹ͢ΔΘ͚Ͱͳ͍ • ࣮༷తʹʮਖ਼֬͞ʯʮ୯ௐੑʯ͕ཁٻ ͞Ε͍ͯΔ
Alternatives of java.lang.Math
commons-math3 org.apache.commons:commons-math3:3.6.1
commons-math3 • FastMath Ϋϥε͕ఏڙ͞Ε͍ͯΔ • java.lang.Math ͱಉ͡ϝιουߏ • ΑΓ͘ɺ͔ͭਫ਼͕ߴ͍͜ͱΛᨳ͍ͬͯΔ •
JIT ʹΑΔ࠷దԽΛલఏͱ͠ɺ·ͨେ͖Ίͷ ϧοΫΞοϓςʔϒϧΛར༻ͯ͠ߴԽΛਤͬ ͍ͯΔ
jafama net.jafama:jafama:2.1.0
jafama • ͪ͜Β FastMath Ϋϥε͕ఏڙ͞Ε͍ͯΔ • 1e-15 (0.000000000000001) ͷਫ਼Β͍͠ •
JIT ʹΑΔ࠷దԽΛલఏͱ͍ͯ͠Δ • ਫ਼Λ٘ਜ਼ʹͨ͠ɺֶؔͷߴ࣮ఏڙ͞ Ε͍ͯΔ • xxxQuick() ͷΑ͏ʹɺ”Quick” ͷαϑΟοΫε͕ ͍͍ͯΔ
Comparison: performance
ܭࢉͷൺֱ • java.lang.Math ͱ commons-math3, jafama ͱΛൺֱ͢Δ • jmh ͰεϧʔϓοτΛܭଌ͢Δ
• ࣍ͷֶؔͦΕͧΕʹ͍ͭͯܭଌ͢Δ • log, log1p, exp, tanh, pow, sqrt • ػցֶशͷ࣮ʹͯΑ͘ར༻͢Δؔ܈Ͱ͢ • ֶؔʹɺεέʔϧͷҟͳΔҾΛෳ༻ҙ͢Δ • ಛఆͷ (۠ؒ) ʹରԠͨ͠࠷దԽ࣮͕͞Ε͍ͯΔ߹ ͕͋ΔͨΊ
ϕϯνϚʔΫϓϩάϥϜ https://github.com/komiya-atsushi/ java-playground/tree/master/math- functions
log
log • commons-math3 ͕಄ͻͱͭൈ͖Μग़͍ͯΔ • 1.234 ͷҾΛ༩͑ͨͱ͖ͷੑೳ͕ҟৗత ʹඈͼൈ͚͍ͯΔ͚Ͳɺ͜ΕΘΓͱී௨ Ͱ͢ •
jafama ͱ jdk ΄΅ಉ͡ੑೳ
log1p
log1p • log ͱҟͳΓɺjafama ͕ѹతʹΑ͍ • jdk ͱ commons-math3 େࠩͳ͍͕ɺ
jdk > commons-math3 Ͱ͋Δ • commons-math3 ͷ log ͷ݁ՌԿͩͬͨ ͷ͔…
exp
exp • commons-math3, jafama ͱʹɺҾ͕େ͖ ͘ͳΔʹͭΕͯੑೳ͕ߴ·Δ • ಛʹ jafama શൠతʹੑೳ͕Α͍
• ҰํͰ jdk …
tanh
tanh • ͍ͣΕͷ࣮ɺҾͷεέʔϧ͕େ͖͘ͳ Δͱɺੑೳ͕Α͘ͳΔ • jafama > commons-math3 > jdk
sqrt
sqrt • େࠩͳ͍ • ͲΕΛͬͯ΄ͱΜͲಉ͡
pow
pow • jafama ϐʔΩʔͰ͋Δ͕ɺશମతʹ༏Ε͍ͯ Δ • jdk ϐʔΩʔա͗Δ • power
͕খ͍͞߹ commons-math3 ΑΓ Α͍ੑೳͰ͋Δ • commons-math3 ຌ༱
Comparison: accuracy
ܭࢉਫ਼ͷൺֱ • java.lang.StrictMath ʹ͓͚Δ࣮ͷΓͱൺֱ͢Δ • (StrictMath ͷ͕ਖ਼͍͠Θ͚Ͱͳ͍ͷ͕ͩ…) • Γಉ࢜ͷࠩʹର͠ɺStrictMath ଆͷΓΛ
ͱׂͯ͠߹Λܭࢉ͢Δ • ͦͷׂ߹ͷฏۉઈରͱ࠷େͰਫ਼ΛݟͯΈΔ • Ҿͷݻఆͤͣɺཚੜͨ͠ͷΛ༩͑Δ
Result: average DPNNPOTNBUI KBGBNB MPH & & MPHQ & &
FYQ & & UBOI & & TRSU & &
Result: maximum DPNNPOTNBUI KBGBNB MPH & & MPHQ & &
FYQ & & UBOI & & TRSU & &
Result • ͍ͣΕʹ͓͍ͯɺେ͖ͳࠩҟ͕͋ΔΘ͚Ͱ ͳ͍ • 1e-15 ͷਫ਼อূͰ͖ͦ͏ • jafama ʹ͍ͭͯɺStrictMath
ͷΓͱҟ ͳΔ͜ͱ͕ଟ͍ʹ͋Γͦ͏
Conclusion
·ͱΊ • ʮۜͷؙଘࡏ͠ͳ͔ͬͨʯ • “FastMath” ͱ໊͍ͬͯͯɺͯ͢ͷֶؔ ͷ࣮ʹ͓͍ͯ JDK ͷ࣮ΑΓ༏Ε͍ͯΔɺͱ ͍͏Θ͚Ͱͳ͍
• ·ͨɺֶؔʹ༩͑ΔҾ࣍ୈͰੑೳ͕େ͖͘ҟΔ ͜ͱ͋Γ͏Δ • ϢʔεέʔεʹԠͯ͡ɺ֤छ࣮Λ͍͚Δ͜ͱ͕ ඞཁ
Thank you!