---
title: "How do I time a method's execution in Java?"  
description: "How do I time a method's execution in Java?"  
author: "Anonymous User"  
published: 2015-08-07  
updated: 2015-08-07  
canonical: https://www.mindstick.com/forum/33403/how-do-i-time-a-method-s-execution-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How do I time a method's execution in Java?

How do I get a [method](https://www.mindstick.com/forum/166/webservice-method)'s [execution](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) time? Is there a [Timer](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) [utility](https://www.mindstick.com/articles/12979/the-utility-of-accounting-tools-for-businesses-and-organizations) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) for things like [timing](https://answers.mindstick.com/qa/97195/what-is-trcd-timing) how long a task takes, etc?\
Most of the searches on [Google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) return [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) for timers that [schedule](https://www.mindstick.com/blog/11999/how-to-schedule-architectural-photography-for-your-building-project) [threads](https://www.mindstick.com/blog/11678/threads-in-java) and tasks, which is not what I want.

## Replies

### Reply by Anonymous User

There is always the old-fashioned way:\

```
long startTime = System.nanoTime();methodToTime();long endTime = System.nanoTime();long duration = (endTime - startTime); 
```


---

Original Source: https://www.mindstick.com/forum/33403/how-do-i-time-a-method-s-execution-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
