---
title: "判断某一段语句执行需要多少时间"
author: "killeraction"
date: "2013-10-31T17:16:53Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-10-31T17:16:53Z"
id: 1967747
url: "https://killeraction.iteye.com/blog/1967747"
---

首先添加maven依赖如下

 

```
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>12.0</version>
</dependency>
```

 

 

具体代码使用方式如下:

```
		Stopwatch stopwatch = new Stopwatch().start();

                //do something test

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

                }

                long nanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);

                System.out.println(nanos);
```