SlideShare a Scribd company logo
Object Comparisons
Finding Prime Numbers
C++ & Java
ADAM FELDSCHER
I699 PERFORMANCE DESIGN PATTERNS II
10/16/2019
Modifications
 All tests are done for primes up to 10k, with 40 iterations
 1k had too much noise
 Java and C++
 Java Primitives vs Wrappers
 PrimeFinder Class Invoction
 New instance per each iteration
 Bring SQRT into for loop comparison
 Adding is_prime method
Algorithm (Java)
for (int iter = 0; iter < max_iter; iter++) {
// insert delays
long start_time = System.nanoTime();
for (int n = 2; n <= max_prime; n++) {// 2 - 10k
int max_divisor = (int) sqrt(n);
boolean is_prime = true;
for (int i = 2; i <= max_divisor; i++) {// check for divisors
if (n % i == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
num_primes_found++; // count primes
}
}
long end_time = System.nanoTime();
// print things
num_primes_found = 0;
}
Java Consistency Check
0
1000000
2000000
3000000
4000000
5000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 10k, normal consistency
Run 1 Run 2
Java Primitives vs Wrappers
Java Primitives vs Wrappers
(Integer)
0
5000000
10000000
15000000
20000000
25000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 10k, Integer
Primative Integer
Java PrimeFinder Class
public class PrimeFinder {
private Integer max_prime;
public PrimeFinder(Integer max_prime) {
this.max_prime = max_prime;
}
public Integer find_primes() {
Integer num_primes_found = 0;
for (Integer n = 2; n <= max_prime; n++) {
Integer max_divisor = (int) sqrt(n);
Boolean is_prime = true;
for (Integer i = 2; i <= max_divisor; i++) {
if (n % i == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
num_primes_found++;
}
}
return num_primes_found;
}
}
public static void main(String[] args) {
for (Integer iter = 0; iter < max_iter; iter++) {
//Start Timer
PrimeFinder primeFinder = new PrimeFinder(iter, max_prime);
num_primes_found = primeFinder.find_primes();
//End timer & Print
}
Java PrimeFinder Class
0
5000000
10000000
15000000
20000000
25000000
30000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 10k, Primefinder
Primative Class PrimeFinder
C++ PrimeFinder Class
class PrimeFinder
{
private:
int _max_prime;
public:
PrimeFinder(int max_prime);
int find_primes();
};
PrimeFinder::PrimeFinder(int max_prime) {
_max_prime = max_prime;
}
int PrimeFinder::find_primes() {
int num_primes_found = 0;
int n;
for (n = 2; n <= _max_prime; n++) {
int max_divisor = (int) sqrt(n);
bool is_prime = true;
int i;
for (i = 2; i <= max_divisor; i++) {
if (n % i == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
num_primes_found++;
}
}
return num_primes_found;
}
C++ PrimeFinder Class
0
200000
400000
600000
800000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
C++ PrimeFinder
C++ Primative C++ PrimeFinder
Java Prime Finder + SQRT
Java Prime Finder + SQRT
0
5000000
10000000
15000000
20000000
25000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 10k, Primefinder
Primative Class PrimeFinder SQRT
C++ PrimeFinder + SQRT
0
200000
400000
600000
800000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
C++ PrimeFinder SQRT
C++ PrimeFinder C++ PrimeFinder SQRT
Java IsPrime Method
public class PrimeFinder {
private Boolean is_prime(Integer n) {
Integer max_divisor = (int) sqrt(n);
for (Integer i = 2; i <= max_divisor; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
public Integer find_primes() {
Integer num_primes_found = 0;
for (Integer n = 2; n <= max_prime; n++) {
if (is_prime(n)) {
num_primes_found++;
}
}
return num_primes_found;
}
}
Java IsPrime Method
0
5000000
10000000
15000000
20000000
25000000
30000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 10k, Integer, PrimeFinder, IsPrime
Primative Class PrimeFinder PrimeFinder IsPrime
C++ IsPrime Method
bool PrimeFinder::is_prime(int n) {
int max_divisor = (int) sqrt(n);
for (int i = 2; i <= max_divisor; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int PrimeFinder::find_primes() {
int num_primes_found = 0;
int n;
for (n = 2; n <= _max_prime; n++) {
if (is_prime(n)) {
num_primes_found++;
}
}
return num_primes_found;
}
C++ IsPrime Method
0
200000
400000
600000
800000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
C++ PrimeFinder isPrime
C++ PrimeFinder C++ PrimeFinder isprime
Java 1K tests
0
1000000
2000000
3000000
4000000
5000000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Nanoseconds
Iteration
Java 10, 1k, Integer Primefinder
Integer Class PrimeFinder

More Related Content

What's hot

Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
ChengHui Weng
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting StartedTeerawat Issariyakul
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
Teerawat Issariyakul
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
Doug Hawkins
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
Guy Korland
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
Andrey Karpov
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWELattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
Priyanka Aash
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
Edge AI and Vision Alliance
 
同態加密
同態加密同態加密
同態加密
峻豪 呂
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf
 
Lattice Cryptography
Lattice CryptographyLattice Cryptography
Lattice Cryptography
Priyanka Aash
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
Platonov Sergey
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
PyData
 
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Sergey Platonov
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
chanchal214
 

What's hot (20)

Yampa AFRP Introduction
Yampa AFRP IntroductionYampa AFRP Introduction
Yampa AFRP Introduction
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWELattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
Lattice-Based Cryptography: CRYPTANALYSIS OF COMPACT-LWE
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
 
同態加密
同態加密同態加密
同態加密
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
Lattice Cryptography
Lattice CryptographyLattice Cryptography
Lattice Cryptography
 
Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2
 
AA-sort with SSE4.1
AA-sort with SSE4.1AA-sort with SSE4.1
AA-sort with SSE4.1
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
Александр Гранин, Функциональная 'Жизнь': параллельные клеточные автоматы и к...
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 

Similar to C++ & Java JIT Optimizations: Finding Prime Numbers

C vs Java: Finding Prime Numbers
C vs Java: Finding Prime NumbersC vs Java: Finding Prime Numbers
C vs Java: Finding Prime Numbers
Adam Feldscher
 
Chapter 2 Method in Java OOP
Chapter 2   Method in Java OOPChapter 2   Method in Java OOP
Chapter 2 Method in Java OOP
Khirulnizam Abd Rahman
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
Khirulnizam Abd Rahman
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
Egor Bogatov
 
06slide.ppt
06slide.ppt06slide.ppt
06slide.ppt
RohitNukte
 
Java performance
Java performanceJava performance
Java performance
Sergey D
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
Prof. Dr. K. Adisesha
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트기룡 남
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functionsTAlha MAlik
 
Import java
Import javaImport java
Import java
heni2121
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
Matt Warren
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
False sharing 隱藏在多核系統的效能陷阱
False sharing 隱藏在多核系統的效能陷阱False sharing 隱藏在多核系統的效能陷阱
False sharing 隱藏在多核系統的效能陷阱
Genchi Lu
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
STAMP Project
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Ontico
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On RandomnessRanel Padon
 
Rx workshop
Rx workshopRx workshop
Rx workshop
Ryan Riley
 

Similar to C++ & Java JIT Optimizations: Finding Prime Numbers (20)

C vs Java: Finding Prime Numbers
C vs Java: Finding Prime NumbersC vs Java: Finding Prime Numbers
C vs Java: Finding Prime Numbers
 
Chapter 2 Method in Java OOP
Chapter 2   Method in Java OOPChapter 2   Method in Java OOP
Chapter 2 Method in Java OOP
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
06slide.ppt
06slide.ppt06slide.ppt
06slide.ppt
 
Java performance
Java performanceJava performance
Java performance
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 
Import java
Import javaImport java
Import java
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
False sharing 隱藏在多核系統的效能陷阱
False sharing 隱藏在多核系統的效能陷阱False sharing 隱藏在多核系統的效能陷阱
False sharing 隱藏在多核系統的效能陷阱
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 

More from Adam Feldscher

Java JIT Performance Testing and Results
Java JIT Performance Testing and ResultsJava JIT Performance Testing and Results
Java JIT Performance Testing and Results
Adam Feldscher
 
Optimizing Java Notes
Optimizing Java NotesOptimizing Java Notes
Optimizing Java Notes
Adam Feldscher
 
Java JIT Improvements Research
Java JIT Improvements ResearchJava JIT Improvements Research
Java JIT Improvements Research
Adam Feldscher
 
Java JIT Optimization Research
Java JIT Optimization Research Java JIT Optimization Research
Java JIT Optimization Research
Adam Feldscher
 
Paper summary
Paper summaryPaper summary
Paper summary
Adam Feldscher
 
Optimizing Java
Optimizing JavaOptimizing Java
Optimizing Java
Adam Feldscher
 
Performance Design Patterns 3
Performance Design Patterns 3Performance Design Patterns 3
Performance Design Patterns 3
Adam Feldscher
 

More from Adam Feldscher (7)

Java JIT Performance Testing and Results
Java JIT Performance Testing and ResultsJava JIT Performance Testing and Results
Java JIT Performance Testing and Results
 
Optimizing Java Notes
Optimizing Java NotesOptimizing Java Notes
Optimizing Java Notes
 
Java JIT Improvements Research
Java JIT Improvements ResearchJava JIT Improvements Research
Java JIT Improvements Research
 
Java JIT Optimization Research
Java JIT Optimization Research Java JIT Optimization Research
Java JIT Optimization Research
 
Paper summary
Paper summaryPaper summary
Paper summary
 
Optimizing Java
Optimizing JavaOptimizing Java
Optimizing Java
 
Performance Design Patterns 3
Performance Design Patterns 3Performance Design Patterns 3
Performance Design Patterns 3
 

Recently uploaded

Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 

Recently uploaded (20)

Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 

C++ & Java JIT Optimizations: Finding Prime Numbers

  • 1. Object Comparisons Finding Prime Numbers C++ & Java ADAM FELDSCHER I699 PERFORMANCE DESIGN PATTERNS II 10/16/2019
  • 2. Modifications  All tests are done for primes up to 10k, with 40 iterations  1k had too much noise  Java and C++  Java Primitives vs Wrappers  PrimeFinder Class Invoction  New instance per each iteration  Bring SQRT into for loop comparison  Adding is_prime method
  • 3. Algorithm (Java) for (int iter = 0; iter < max_iter; iter++) { // insert delays long start_time = System.nanoTime(); for (int n = 2; n <= max_prime; n++) {// 2 - 10k int max_divisor = (int) sqrt(n); boolean is_prime = true; for (int i = 2; i <= max_divisor; i++) {// check for divisors if (n % i == 0) { is_prime = false; break; } } if (is_prime) { num_primes_found++; // count primes } } long end_time = System.nanoTime(); // print things num_primes_found = 0; }
  • 4. Java Consistency Check 0 1000000 2000000 3000000 4000000 5000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 10k, normal consistency Run 1 Run 2
  • 6. Java Primitives vs Wrappers (Integer) 0 5000000 10000000 15000000 20000000 25000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 10k, Integer Primative Integer
  • 7. Java PrimeFinder Class public class PrimeFinder { private Integer max_prime; public PrimeFinder(Integer max_prime) { this.max_prime = max_prime; } public Integer find_primes() { Integer num_primes_found = 0; for (Integer n = 2; n <= max_prime; n++) { Integer max_divisor = (int) sqrt(n); Boolean is_prime = true; for (Integer i = 2; i <= max_divisor; i++) { if (n % i == 0) { is_prime = false; break; } } if (is_prime) { num_primes_found++; } } return num_primes_found; } } public static void main(String[] args) { for (Integer iter = 0; iter < max_iter; iter++) { //Start Timer PrimeFinder primeFinder = new PrimeFinder(iter, max_prime); num_primes_found = primeFinder.find_primes(); //End timer & Print }
  • 8. Java PrimeFinder Class 0 5000000 10000000 15000000 20000000 25000000 30000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 10k, Primefinder Primative Class PrimeFinder
  • 9. C++ PrimeFinder Class class PrimeFinder { private: int _max_prime; public: PrimeFinder(int max_prime); int find_primes(); }; PrimeFinder::PrimeFinder(int max_prime) { _max_prime = max_prime; } int PrimeFinder::find_primes() { int num_primes_found = 0; int n; for (n = 2; n <= _max_prime; n++) { int max_divisor = (int) sqrt(n); bool is_prime = true; int i; for (i = 2; i <= max_divisor; i++) { if (n % i == 0) { is_prime = false; break; } } if (is_prime) { num_primes_found++; } } return num_primes_found; }
  • 10. C++ PrimeFinder Class 0 200000 400000 600000 800000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration C++ PrimeFinder C++ Primative C++ PrimeFinder
  • 12. Java Prime Finder + SQRT 0 5000000 10000000 15000000 20000000 25000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 10k, Primefinder Primative Class PrimeFinder SQRT
  • 13. C++ PrimeFinder + SQRT 0 200000 400000 600000 800000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration C++ PrimeFinder SQRT C++ PrimeFinder C++ PrimeFinder SQRT
  • 14. Java IsPrime Method public class PrimeFinder { private Boolean is_prime(Integer n) { Integer max_divisor = (int) sqrt(n); for (Integer i = 2; i <= max_divisor; i++) { if (n % i == 0) { return false; } } return true; } public Integer find_primes() { Integer num_primes_found = 0; for (Integer n = 2; n <= max_prime; n++) { if (is_prime(n)) { num_primes_found++; } } return num_primes_found; } }
  • 15. Java IsPrime Method 0 5000000 10000000 15000000 20000000 25000000 30000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 10k, Integer, PrimeFinder, IsPrime Primative Class PrimeFinder PrimeFinder IsPrime
  • 16. C++ IsPrime Method bool PrimeFinder::is_prime(int n) { int max_divisor = (int) sqrt(n); for (int i = 2; i <= max_divisor; i++) { if (n % i == 0) { return false; } } return true; } int PrimeFinder::find_primes() { int num_primes_found = 0; int n; for (n = 2; n <= _max_prime; n++) { if (is_prime(n)) { num_primes_found++; } } return num_primes_found; }
  • 17. C++ IsPrime Method 0 200000 400000 600000 800000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration C++ PrimeFinder isPrime C++ PrimeFinder C++ PrimeFinder isprime
  • 18. Java 1K tests 0 1000000 2000000 3000000 4000000 5000000 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Nanoseconds Iteration Java 10, 1k, Integer Primefinder Integer Class PrimeFinder

Editor's Notes

  1. Retest in linux….
  2. Significant! Scale difference from last
  3. Surprising that there’s not more change
  4. Gets entirely optimized out
  5. Almost no impact
  6. Some weirdness, not sure if it jits faster because there are smaller units, or if its just noise. JIT LOG
  7. No change
  8. 1k has more details but also more noise. Linux