Meter


Source link: https://github.com/OleksandrKucherenko/meter

State

Active development, started at: 2014-07-13

Current state: on hold. Collecting devs feedback.

What is meter?

Meter - is a simple micro-benchmarking tool for Android (not only for Android, its actually for any Java project).

It was designed for Android. Meter try to make measurement an easy task, with minimal impact on total project performance.

By using it you can easily benchmark critical components of own Android Projects and select the best possible way based on real measurments, instead of making gueses. It can be easily attached to jUnits and on each run will confirm performance choices.

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

(C) Donald Knuth - http://en.wikiquote.org/wiki/Donald_Knuth

Include Into Project

repositories {

  maven {

url  "http://dl.bintray.com/kucherenko-alex/android"
  
}
 
}
  dependencies {

  // ALTERNATIVE:
  //
compile(group: 'com.artfulbits', name: 'meter', version: '1.0.1.164', ext: 'aar')
  compile 'com.artfulbits:meter:+@aar' 
}

Changes Log

v1.0.1.164

  • ADD: compare of tracked steps by Total value with custom accuracy
  • ADD: JAR binray generated for Maven repository. Hope it will resolve issues with library attaching to projects.

Changes Log

Advanced topics

Accuracy of Measurements

Configuration

Custom Logs

Android Performance Results

Unit Testing

Proguard

Output Preview

Design objectives

  • minimalistic code
  • deployment in one file
  • no support of scenarios that has more than 256 steps
  • nested measurements
  • measurement of loops/iterations:
  • loops with known number of iterations
  • loops with unknown number of iterations (round array in use, 1000 steps of loop used for average calculations)
  • loop Min/Max/Average cost of iteration
  • no sub-steps inside the loops, but allowed sub-measurement
  • measurement limited by one thread (partly limited by class design, its just a recommendation not an actual limit)
  • minimalistic allocations during benchmarking, all calculations and allocations are done only on Meter.stats() call
  • logcat as standard output. Developer can change output class instance to any required. Simple interface to inherit/implement.
  • simple configuration of output formats. Boolean flags mostly.
  • nanos timestamps used for time calculations, millis for time output
  • support Android native traceview benchmarking/profiling

Calls Protocol

Sample of typical micro benchmark:

  // ... create/get instance for tests ...
final static Meter sMeter = Meter.getInstance();

 public void test_00_mainProtocol() {

  // ... start the play! ...
  sMeter.start("test_00_mainProtocol");

// ... do some warm up steps ...
  sMeter.skip("warm up of the classes");

// ... do some logic steps #1 ...
  sMeter.beat("logic step execution #1 ");

// ... do some logic steps #2 ...
  sMeter.beat("logic step execution #2");

sMeter.loop(100, "reserve space for 100 loops");

  for( int i =0; i < 100; i++ ){

  // ... do some iteration logic ...

 sMeter.recap();

  
}

  sMeter.unloop("");

sMeter.finish("END of test_00_mainProtocol()");

}

Step 0 - Get Instance

All activities with micro-benchmarking should be started from call Meter.getInstance() - this is the entry point. You can choose would you want to keep reference in local variable or each time call the method. Inside the method implemented simplest cache-map WeakHashMap<Thread, Meter> which keeps association of thread with Meter instance. In most cases you will need only one Meter instance per thread.

  final Meter mMeter = Meter.getInstance();

 /** Get instance of the benchmark tool. */
public Meter meter() {

  return mMeter;

}

Step 1 - Start and Finish

To start benchmarking you should call a corresponding method meter().start("{ comment } ") and of course to finish the job call one proposed methods meter().end("{ comment } ") or meter().finish("{ comment } ").

meter().end("{ comment } ") - stops benchmarking, but does not remove results from 'stack'. That allows to do some manipulations and should be used for 'nested' measurements. After this call you should not forget to call meter().pop().

meter().finish("{ comment } ") - stops benchmarking, removing 'measurement' from 'stack' and print results. This is recommended method to call at the end of benchmark.

Step 2 - Beats

Available two commands: meter().beat("{ comment } ") and meter().skip("{ comment } "). First one create timestamp that participate in calculations of execution costs, second one excluding tracked step from calculations.

So we have ability to create complex scenarios with included and excluded steps.

Step 3 - Loops

In class exists three API methods for loops benchmarking: meter().loop(int,"{ comment } "), meter().unloop("{ comment } ") and meter().recap(). First two APIs defining the scope of the loop, third one - timestamp iteration inside the loop.

  • Loops can be nested.
  • If you call loop(int,"{ comment } ") - than first parameter define the quantity of iterations to track. This allows to benchmark without mistakes of computations.
  • if you call loop("{ comment } ") - than class become prepared for loops with unknown number of iterations. Its a smart operation and if tracked number of iterations is less than 1000 (1 thousand) - we got computations without mistakes, otherwise will be always a small computation mistake.

That's it. Don't forget to call meter().finish("{ comment } ") for getting results in logcat.

License

Copyright 2015 Oleksandr Kucherenko Copyright 2005-2015 ArtfulBits, Inc. (http://www.artfulbits.com)  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

okio made easy, yo.

A Searchable Spinner with customizable color and a nice reveal animation.

The Sweetest way into connecting to your server. Now min SDK is 3!

This is an Image slider with swipes.

The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.

  • EasyMoneyEditText and EasyMoneyTextView widgets
  • Custom currency support added through string symbol, Locales, or Currency objects
  • Commas formatting support added
  • Show/hide currency symbol
  • Show/hide commas in the widgets
  • Get raw value in string or formatted value in string

RxTasks is a lightweight wrapper for the GMS Tasks API, more commonly recognized when using asynchronous results from Firebase requests.

Typically the Tasks API would allow you to add listeners that may be scoped to an activity or executor, however this is not needed since scheduling and Disposable's are handled by the user.

Please note that this library uses RxJava2 so calls must respect Completable and Single chains.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes