Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Created July 9, 2012 16:16
Show Gist options
  • Save nicerobot/3077399 to your computer and use it in GitHub Desktop.
Save nicerobot/3077399 to your computer and use it in GitHub Desktop.
Problems with nanoTime in Java under Linux
#!/bin/sh
cd /tmp
cat >t.java <<CLASS
class t { public static void main(String...args) {
System.out.println(System.currentTimeMillis()+"\n"+System.nanoTime()); } }
CLASS
uname -rvsp
date -u
date +%s
javac t.java && java -cp . t
echo
java -version
Darwin 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:33:05 PDT 2012; root:xnu-1699.26.8~1/RELEASE_I386 i386
Mon Jul 9 16:07:05 UTC 2012
1341850026
1341850026961
1341850026961520000
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
Linux 2.6.32-100.28.5.el6.x86_64 #1 SMP Wed Feb 2 18:40:23 EST 2011 x86_64
Mon Jul 9 16:07:12 UTC 2012
1341850032
1341850032833
1537280191304635
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) Server VM (build 22.1-b02, mixed mode)
Linux 2.6.32-100.23.1.el5 #1 SMP Tue Nov 9 16:19:09 EST 2010 x86_64
Mon Jul 9 08:12:16 UTC 2012
1341821536
1341821536761
2837617505717985
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
Linux 2.6.18-164.0.0.0.1.el5 #1 SMP Thu Sep 3 00:21:28 EDT 2009 x86_64
Mon Jul 9 16:07:18 UTC 2012
1341850038
1341850039349
20983226427109720
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
Linux 2.6.18-308.1.1.0.1.el5 #1 SMP Wed Mar 7 11:35:00 EST 2012 i686
Mon Jul 9 16:07:09 UTC 2012
1341850029
1341850030398
780466134862302
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment