Mercurial > hg > Members > tatsuki > jungle-bench
view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle_core/AtomicBench.java @ 20:195c1a644550
benchmark add
author | tatsuki |
---|---|
date | Tue, 17 Mar 2015 15:37:19 +0900 |
parents | |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle_core; import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.lang.Integer;import java.lang.InterruptedException;import java.lang.Runtime;import java.lang.String;import java.lang.System;import java.util.concurrent.atomic.AtomicReference; /** * Created by e115731 on 15/03/11. */ public class AtomicBench { public static void main(String args[]) throws IOException { Runtime rt = Runtime.getRuntime(); int cpuNum = rt.availableProcessors(); System.out.println("CPUCount = " + cpuNum); File file = new File("strCount"); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); AtomicReferenceTest ref = new AtomicReferenceTest(0); for (int count = 1; count <= cpuNum; count++) { readAtomicReservableReferenceThread th[] = new readAtomicReservableReferenceThread[count]; for (int tcount = 0; tcount < count; tcount++) { th[tcount] = new readAtomicReservableReferenceThread(ref); th[tcount].start(); } try { java.lang.Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } long readCount = 0; for (int tcount = 0; tcount < count; tcount++) { th[tcount].set(false); System.out.println(th[tcount].get()); readCount = readCount + th[tcount].get(); } System.out.println("----------------------Thread Stop--------------------------------------------"); pw.println(count + " " + readCount); System.out.println("ThreadTest count = " + count); System.out.println("read count = " + (readCount)); } pw.close(); System.out.println("-----------end--------------------------------------------------------"); } }