Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:43:32+00:00 2026-05-27T19:43:32+00:00

I have been looking into benchmarking lately, I have always been interested in logging

  • 0

I have been looking into benchmarking lately, I have always been interested in logging program data etc. I was interested in knowing if we can implement our own memory usage code and implement our own time consumption code efficently inside our program. I know how to check long it takes for a code to run:

public static void main(String[]args){
        long start = System.currentTimeMillis();
        // code
        System.out.println(System.currentTimeMillis() - start);
    }

I also looked into Robust Java benchmarking, Part 1: Issues, this tutorial is very comprehensive. Displays the negative effects of System.currentTimeMillis();. The tutorial then suggests that we use System.nanoTime(); (making it more accurate?).

I also looked at Determining Memory Usage in Java for memory usage. The website shows how you can implement it. The code that has been provided looks inefficent because the person is calling

long L = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

After this he calls System.gc(); (4 * 4) = 16 times. Then repeating the process again.
Doesn’t this also take up memory?

So in conlusion, is it possible to implement an efficent benchmarking code inside your java program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:43:33+00:00Added an answer on May 27, 2026 at 7:43 pm

    Yes it is possible to effectively implement performance benchmarks in java code. The important question is that any kind of performance benchmark is going to add its own overhead and how much of it do you want. System.currentMill..() is good enough benchmark for performance and in most of the cases nanoTime() is an overkill.

    For memory System.gc will show you varied results for different runs (as gc run is never guranteed.) I generally use Visual VM for memory profiling (its free) and then use TDA for dumps analyzing.

    One way to do it less invasively is using Aspect oriented programing. You can create just one Aspect that runs on a particular Annotation or set of methods and write an @Around advice to collect performance data.

    Here is a small snippet:

    public class TestAspect {
    
        @LogPerformance
        public void thisMethodNeedsToBeMonitored(){
            // Do Something
        }
        public void thisMethodNeedsToBeMonitoredToo(){
            // Do Something
        } 
    }
    
    @interface LogPerformance{}
    
    @Aspect
    class PerformanceAspect{
        @Around("the pointcut expression to pick up all " +
                "the @PerfMonitor annotated methods")
        public void logPerformance(){
            // log performance here
            // Log it to a file
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into Spring Social Facebook's publish(objectId, connectionName, data) API , but
I have been looking into using Boost.Interprocess to create a disk-backed data structure. The
I have been looking into different algorithms lately and have read quite alot about
I have been looking into this for a while and can't figure it out.
So i have been looking into JNI calls so i can interact with some
I have been looking into this for some hours now and can't figure it
I have been looking into recursion and TCO. It seems that TCO can make
I have been looking into webkit HTML offscreen rendering lately, but i am unable
I have been looking into Code First with Entity Framework CTP4 and you can
I have been looking into CruiseControl configuration recently (I'm a complete CC noob) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.