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

  • Home
  • SEARCH
  • 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 6600065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:34:23+00:00 2026-05-25T18:34:23+00:00

I was given a weird task. I have to refactor certain methods in a

  • 0

I was given a weird task. I have to refactor certain methods in a huge code base (the easy part) and provide performance gain reports. I should focus on speed of execution and memory usage. They want know the performance improvement by method!

So I have a method like this:

public void processHugeFile(File f) {
   long start = java.lang.System.currentTimeMillis();

   // lots of hashmaps, lots of arrays, weird logic,...

   long end = java.lang.System.currentTimeMillis();
   logger.log("performance comparison - exec time: " + (end - start));
}

Then I have to refactor it:

public void processHugeFile(File f) {
   long start = java.lang.System.currentTimeMillis();

   // just lists, some primitives, simple logic,...

   long end = java.lang.System.currentTimeMillis();
   logger.log("performance comparison - exec time: " + (end - start));
}

In the end I just have to process the logs.

But what about memory usage? I have tried getRuntime().totalMemory() - getRuntime().freeMemory() and the getHeapMemoryUsage().getUsed() but they don’t seem to work. Also, JVM Profilers focus on objects not on methods and I am speaking of a fairly large code base.

Can someone provide me some hints?

Thank you very much.

  • 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-25T18:34:24+00:00Added an answer on May 25, 2026 at 6:34 pm

    Broadly, refactoring is not a means to increase performance, but to improve readability and maintainability of a code base. (Which may then help you make optimizations and architectural changes with more confidence and ease.) I assume you’re aware of this, and you mean that you’re trying to clean up some slow code in the process.

    This is really a tool for a profiler, not for hand-instrumentation. You will never get precise measurements this way. For example, System.currentTimeMillis() calls add their own overhead and for short-lived methods could take longer than the method itself. Runtime can only help you get a crude picture of memory usage.

    I don’t agree that profilers can’t help. JProfiler for instance will happily graph heap size over time, include generation sizes. It will break down memory usage by allocation site, object type. It will show you performance bottlenecks by inclusive/exclusive time. And all of this without touching your code.

    You really, really want to use a profiler like JProfiler, not hand-coded stuff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a little weird task. The following (stripped) code is given (but i
I have the unfortunate task of cleaning up a bunch of old ColdFusion code.
UITableView custom cell showing weird results? I have my code below. Everything was showing
i Have been given this simple task , I want to connect to facebook
I have the following weird requirement. I am given: A list of some method
I have been given the task of using java to produce a Sin table,
Given a Python object of any kind, is there an easy way to get
What i want to do is create a function that given a certain length
I have a weird issue. Say you have the following: Application.ThreadException += something; try
As the termplot function in R is containing some weird code that is giving

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.