Comments (7)
Hi @dedece35,
thank you for ideas. I agree with you to benchmark other kind of loops.
from ecocode.
I don't know where this rule comes from but it's for sure not part of the Android-specific plugin
from ecocode.
I think this rule has to do with Java performance with Collections. As i know, Foreach and Stream API is convenient to work with Collections.
from ecocode.
Hi @oussamaLaribi ,
I think @durandx would like to have an evidence to confirm what you said. I agree with @durandx. If we don't have a paper, it would b great to do benchmark test to check it (for example with JMH framework for example)
But this discussion goes is a general discussion : how to prove that each implemented rule is legitimate.
what's your opinion @olegoaer, @jules-delecour-dav, @glalloue, @mdubois81 ?
from ecocode.
Hello @dedece35, I have made a benchmark to test the example in the description of the rule. Here’s the code and the result. I'm kinda surprised.
https://github.com/oussamaLaribi/jmh-benchmark-JAVA-S53-rule
from ecocode.
Hi @oussamaLaribi ,
ok. good for micro-benchmark with JMH !
but In your code, there are some useless code. The unit test is useless for me, because benchmark is enough to prove it.
Another idea, is to benchmark other kind of loops. For example, to benchmark a stream, or standard for loop with simple index.
from ecocode.
Thank you @oussamaLaribi for the benchmark. So if I understand correctly, looping from an Array is quicker than from a List, the exact opposite that said by the S53 rule !
To be sure, I made some more tests with JMH.
I added a test where the Arrays.asList
is not prebaked (as I would "correct" my code regarding this rule).
I also added a .stream().forEach
as suggested (I'm curious too 😄).
With a big list (1_000_000 items) :
Benchmark Mode Cnt Score Error Units
BenchmarkForEach.forEachArray avgt 5 2440,479 ± 24,270 us/op
BenchmarkForEach.forEachList avgt 5 4681,401 ± 85,861 us/op
BenchmarkForEach.forEachList2 avgt 5 4722,169 ± 99,151 us/op
BenchmarkForEach.stream avgt 5 4403,399 ± 329,694 us/op
With a small list (10 items) :
Benchmark Mode Cnt Score Error Units
BenchmarkForEach.forEachArray avgt 5 0,027 ± 0,002 us/op
BenchmarkForEach.forEachList avgt 5 0,038 ± 0,002 us/op
BenchmarkForEach.forEachList2 avgt 5 0,042 ± 0,003 us/op
BenchmarkForEach.stream avgt 5 0,038 ± 0,002 us/op
With these tests I constantly have better performance on arrays...
from ecocode.
Related Issues (20)
- License issue HOT 6
- UnnecessarilyAssignValuesToVariables NullPointerException HOT 1
- Documentation of Java backend rules HOT 1
- The rule "The variable value is not assigned" (JAVA) can report false positives. HOT 1
- Merge RTE code HOT 2
- No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range HOT 2
- Can't build CodeNarc HOT 6
- Quality gates and Quality profiles not visible HOT 2
- Is it possible to add "eco-conception" tag on existing built-in rules ? HOT 6
- [Java plugin] Compilation error with jdk 1.8 compliance HOT 4
- Migration compilation to Java 11 HOT 5
- Crash au lancement du container sonar HOT 1
- codenarc 2.2.3 referenced but not available on Maven central HOT 10
- Quelques questions HOT 1
- Dependance Maven codenarc inconnue (v2.2.1) HOT 5
- Use single quote (') instead of quotation mark (") is only available with js/ts HOT 3
- "Using strings as arguments to SetTimeout() and setInterval()" rule is maybe only available with js/ts HOT 1
- [Sonarqube Server] Integration incompatible between v9.4-community and php-plugin HOT 3
- Rename parent folder following maven convention HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ecocode.