Giter VIP home page Giter VIP logo

bench-filters's Introduction

Applying multiple filters with Guava

This is a micro-benchmark using JMH to compare the time it takes to apply 2 consecutive filters to a collection, using either Predicates.and() in a single filter() call or several filter() calls.

What does it do?

The baseline just returns the first element of the collection using FluentIterable.first(). There are then 4 different configurations of filters tested, using either method:

  1. Both filters match in all cases
  2. The first filter only matches some of the elements
  3. The last filter only matches some of the elements
  4. The last filter only matches some of the elements, and a third (always true) filter is inserted between the existing 2, to illustrate the impact of a megamorphic method call (at least 3 implementations known by the JVM)

How to compile

The project uses Maven 2+, so just do:

    mvn clean package

How to run

    java -jar target/benchmarks.jar

Results

On my i7-2600 CPU @ 3.40GHz running Ubuntu Saucy and a 64-bit Oracle JDK (1.7u40), I get the following results (reordered to match the description of the configurations):

Benchmark                                                    Mode   Samples        Score  Score error    Units
c.e.j.FilteringBenchmark.baseline                            avgt         9       15.405        0.481    ns/op
c.e.j.FilteringBenchmark.andedFiltersAlwaysMatch             avgt         9       45.335        1.078    ns/op
c.e.j.FilteringBenchmark.chainedFiltersAlwaysMatch           avgt         9       55.216        2.071    ns/op
c.e.j.FilteringBenchmark.andedFiltersPartialMatchFirst       avgt         9       77.658        1.827    ns/op
c.e.j.FilteringBenchmark.chainedFiltersPartialMatchFirst     avgt         9       74.538        4.436    ns/op
c.e.j.FilteringBenchmark.andedFiltersPartialMatchLast        avgt         9       79.416        2.858    ns/op
c.e.j.FilteringBenchmark.chainedFiltersPartialMatchLast      avgt         9       85.599        4.519    ns/op
c.e.j.FilteringBenchmark.anded3FiltersPartialMatchLast       avgt         9      152.213       10.560    ns/op
c.e.j.FilteringBenchmark.chained3FiltersPartialMatchLast     avgt         9      127.748        8.172    ns/op

As expected, the 2 methods are mostly equivalent, though the megamorphic method call does exhibit a significant difference between them.


Licensed under the Apache License, Version 2.0

bench-filters's People

Contributors

fpavageau avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.