How to measure time taken by Java code?

This question already has an answer here: How do I write a correct micro-benchmark in Java? 11 answers You can get nanosecond resolution, even, using System.nanoTime() . However, you may want to consider the points in the following: How do I write a correct micro-benchmark in Java? Say you have a particular method that you would like to put under the microscope. You can do that as fol

如何测量Java代码所花费的时间?

这个问题在这里已经有了答案: 我如何在Java中编写正确的微基准测试? 11个答案 您甚至可以使用System.nanoTime()获得纳秒级分辨率。 但是,您可能需要考虑以下几点: 我如何在Java中编写正确的微基准测试? 假设你有一种特定的方法,你想放在显微镜下。 你可以这样做,如下所示: long time1 = System.nanoTime(); thatMethod(); long time2 = System.nanoTime(); long timeTaken = time2 - time1; System.out.pr

Create quick/reliable benchmark with java?

I'm trying to create a benchmark test with java. Currently I have the following simple method: public static long runTest(int times){ long start = System.nanoTime(); String str = "str"; for(int i=0; i<times; i++){ str = "str"+i; } return System.nanoTime()-start; } I'm currently having this loop multiple times within another loop that is h

用java创建快速/可靠的基准测试?

我正在尝试使用java创建基准测试。 目前我有以下简单的方法: public static long runTest(int times){ long start = System.nanoTime(); String str = "str"; for(int i=0; i<times; i++){ str = "str"+i; } return System.nanoTime()-start; } 我目前在多次发生的另一个循环中多次使用此循环,并获取运行此方法所需的最小/最大/平均时间。 然后我在另一个线程上开始一些

System.currentTimeMillis vs System.nanoTime

Accuracy Vs. Precision What I would like to know is whether I should use System.currentTimeMillis() or System.nanoTime() when updating my object's positions in my game? Their change in movement is directly proportional to the elapsed time since the last call and I want to be as precise as possible. I've read that there are some serious time-resolution issues between different operat

System.currentTimeMillis与System.nanoTime

精度与Vs. 精确 我想知道的是在我的游戏中更新我的对象位置时,我应该使用System.currentTimeMillis()还是System.nanoTime() ? 他们的运动变化与自上次调用以来的时间成正比,我希望尽可能精确。 我已经读过,不同操作系统之间存在一些严重的时间分辨率问题(即Mac / Linux具有近1ms的分辨率,而Windows具有50ms的分辨率?)。 我主要在Windows上运行我的应用程序,并且50毫秒的分辨率看起来相当不准确。 有没有比

32 OR 64 BIT for the JVM?

While reading this book over here. I can see the following section, which says: 32 OR 64 BIT? If you have a 32-bit operating system, then you must use a 32-bit version of the JVM. If you have a 64-bit operating system, then you can choose to use either the 32- or 64-bit version of Java. Don't assume that just because you have a 64-bit operating system, you must also use a 64-bit versio

用于JVM的32位或64位?

在这里阅读这本书。 我可以看到以下部分,其中说: 32或64位? 如果你有一个32位的操作系统,那么你必须使用一个32位版本的JVM。 如果您有一个64位操作系统,那么您可以选择使用32位或64位版本的Java。 不要以为你有一个64位的操作系统,你还必须使用64位版本的Java。 如果您的堆的大小将小于大约3 GB,则32位版本的Java将更快并且占用空间更小。 这是因为JVM中的内存引用只有32位,操作这些内存引用比操作64位引用(

MongoDb and NoSQL Databases Comparision (working with XML Documents)

I am working on a project using Java and Spring 3. There is a new task for me. There will be Xml files and I get that files and convert them into Objects. After that I will put them into a database. The main topic for me to examine nosql databases. CouchDb and MongoDb are the databases I should search. I will make search on that objects(one of the index type will be date and I will make dat

MongoDb和NoSQL数据库比较(使用XML文档)

我正在使用Java和Spring 3开展一个项目。对我来说有一项新任务。 将会有Xml文件,我会得到这些文件并将它们转换为Objects。 之后,我会将它们放入数据库中。 我主要研究nosql数据库的主题。 CouchDb和MongoDb是我应该搜索的数据库。 我将在数据库上search该对象(其中一种索引类型将是日期,我将在选择之间生成日期)。 Performance对我而言非常重要 我将处理一个huge data这就是为什么我应该搜索nosql数据库。 根据

Understanding 'TypeElement' and 'DeclaredType' interface in java

One usage of these two interface, is to write annotation processor. As a java beginner, I find the level of indirection that is added by these two packages: javax.lang.model.element & javax.lang.model.type to provide metadata about java interface and java class confusing. ......... java doc comments say, TypeElement represents a class or interface program element. Provides access to

在java中理解'TypeElement'和'DeclaredType'接口

这两个接口的一个用法是编写注释处理器。 作为一名java初学者,我发现这两个包添加的间接级别: javax.lang.model.element和javax.lang.model.type以提供关于java interface和java class元数据混淆。 ......... java doc评论说, TypeElement表示一个class或interface程序元素。 提供有关类型及其成员的信息。 请注意, enum类型是一种类,注释类型是一种interface 。 DeclaredType表示声明的类型, class类型或inte

How To Do Recursive Observable Call in RxJava?

I am quite new to RxJava (and Reactive paradigm in general), so please bear with me. Suppose I have this News and this nested Comment data structure: public class News { public int id; public int[] commentIds; //only top level comments public News(int id, int[] commentIds) { this.id = id; this.commentIds = commentIds; } } public class Comment { public int id; public int pa

如何在RxJava中执行递归Observable调用?

我对RxJava(以及一般的反应模式)颇为陌生,所以请耐心等待。 假设我有这个News和这个嵌套的Comment数据结构: public class News { public int id; public int[] commentIds; //only top level comments public News(int id, int[] commentIds) { this.id = id; this.commentIds = commentIds; } } public class Comment { public int id; public int parentId; //ID of parent News or parent comment

Java: Convert int[] to smallest representation as ranges

Given an array of int values, how could one parse the series into counting sequence notation? Examples: {1, 2, 3, 4, 5, 9, 13, 14, 15} -> "1-5,9,13-15" {4, 6, 8, 10, 11, 12, 15, 17} -> "4,6,8,10-12,15,17" I'm looking for a method that would produce these results. This is what I have so far, but I'm very much stumped at this point: Test Code: import java.util.Arrays; public

Java:将int []转换为范围的最小表示形式

给定一个int值的数组,如何将这个序列解析为计数序列符号? 例子: {1, 2, 3, 4, 5, 9, 13, 14, 15} -> "1-5,9,13-15" {4, 6, 8, 10, 11, 12, 15, 17} -> "4,6,8,10-12,15,17" 我正在寻找一种能产生这些结果的方法。 这是我迄今为止所做的,但是我非常难以忍受这一点: 测试代码: import java.util.Arrays; public class TestSequencing { public static void main(String[] args) { int[] numbers1

Get screenshot of startmenu

I am using bitblt to to capture a window. If the aero theme is enabled, The background of the captured image is black. If I disable the DWM and capture the window then the captured image is very good. Here is part of my code. HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(desktopDC); HDC windowDC = User32.INSTANCE.GetDC(window); HWND window= User32Extra.INSTANCE.FindWindow(null, "Start me

获取startmenu的截图

我正在使用bitblt来捕获一个窗口。 如果启用了航空主题,则捕获图像的背景为黑色。 如果我禁用DWM并捕获窗口,则捕获的图像非常好。 这是我的代码的一部分。 HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(desktopDC); HDC windowDC = User32.INSTANCE.GetDC(window); HWND window= User32Extra.INSTANCE.FindWindow(null, "Start menu"); GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, desktopDC, 0,

Middleware for MongoDB or CouchDB with jQuery Ajax/JSON frontend

I've been using the following web development stack for a few years: java/spring/hibernate/mysql/jetty/wicket/jquery For certain requirements, I'm considering switching to a NoSQL datastore with an AJAX frontend. I would probably build the frontend with jQuery and communicate with the web application middleware using JSON. I'm leaning toward MongoDB because of more dynamic query

MongoDB或带有jQuery Ajax / JSON前端的CouchDB的中间件

我几年来一直在使用以下Web开发堆栈: 的java /弹簧/休眠/ MySQL的/码头/检票/ jquery的 对于某些要求,我正在考虑使用AJAX前端切换到NoSQL数据存储。 我可能会用jQuery构建前端,并使用JSON与Web应用程序中间件进行通信。 由于更具动态查询能力,我倾向于MongoDB,但我仍在考虑CouchDB。 我不确定在中间使用什么。 可能是RESTful的东西? 我的选择是坚持使用Java(或者Scala或Groovy),因为我使用Drools这样的工具来