Package xbird.util.datetime

Examples of xbird.util.datetime.StopWatch


                f.create(false);
                f.flush(true, true);
                System.err.println("Created BFile: " + btreePath);
                f.close();
            } else if(args[0].equals("import")) {
                StopWatch sw = new StopWatch("elasped time");
                BTree f = new BTree(new File(btreePath));
                f.open();
                FileInputStream fis = new FileInputStream(args[1]);
                DataInputStream dis = new DataInputStream(fis);
                int i = 0;
                while(dis.available() > 0) {
                    String val = dis.readLine().trim();
                    assert (val.length() > 0);
                    f.addValue(new Value(val.getBytes("UTF-8")), i++);
                }
                fis.close();
                f.flush();
                f.close();
                System.err.println(sw);
            } else if(args[0].equals("export")) {
                StopWatch sw = new StopWatch("elasped time");
                BTree f = new BTree(new File(btreePath));
                f.open();
                FileOutputStream fos = new FileOutputStream(args[1]);
                final PrintStream ps = new PrintStream(fos);
                f.search(new BasicIndexQuery.IndexConditionANY(), new CallbackHandler() {
                    public boolean indexInfo(Value value, long pointer) {
                        ps.println(value);
                        return true;
                    }
                    public boolean indexInfo(Value key, byte[] value) {
                        throw new IllegalStateException();
                    }
                });
                fos.close();
                f.close();
                System.err.println(sw);
            } else if(args[0].equals("find")) {
                StopWatch sw = new StopWatch("elasped time");
                BTree f = new BTree(new File(btreePath));
                f.open();
                long ptr = f.findValue(new Value(args[1]));
                System.out.println(ptr);
                f.close();
                System.err.println(sw);
            } else if(args[0].equals("count")) {
                StopWatch sw = new StopWatch("elasped time");
                BTreeIndexer indexer = new BTreeIndexer(new File(btreePath));
                IndexMatch matched = indexer.find(new BasicIndexQuery.IndexConditionEQ(new Value(args[1])));
                System.out.println(matched.countMatched());
                System.err.println(sw);
            } else if(args[0].equals("add")) {
                StopWatch sw = new StopWatch("elasped time");
                BTree f = new BTree(new File(btreePath));
                f.open();
                long pointer = Long.parseLong(args[2]);
                System.err.println("add key: " + args[1] + ", value: " + pointer);
                long old = f.addValue(new Value(args[1]), pointer);
View Full Code Here


        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        reader.setContentHandler(new NopHandler());
        StopWatch sw = new StopWatch("Sax parse time");
        reader.parse(new InputSource(new FileInputStream(XML_FILE)));
        System.err.println(sw);
    }
View Full Code Here

        OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean();
        final com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx;
        long startCpuTime = sunmx.getProcessCpuTime();

        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength + ", pageSize: "
                + pageSize);

        final Segments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];
        final ReadWriteLock rwlock = new ReentrantReadWriteLock();

        final boolean isGCLOCK = (algo == ReplacementAlgorithm.GClock);

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final Status stat = new Status();
            final int thrdnum = i;
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            if(useRWlock) {
                                if(isGCLOCK) {
                                    runBenchmarkWithZipfDistributionReadWriteLockForGCLOCK(rwlock, thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                                } else {
                                    runBenchmarkWithZipfDistributionReadWriteLock(rwlock, thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                                }
                            } else {
                                runBenchmarkWithZipfDistributionSync(thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                            }
                        } else {
                            if(isGCLOCK) {
                                runBenchmarkWithZipfDistributionLockForGCLOCK(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                            } else {
                                runBenchmarkWithZipfDistributionLock(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                            }
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        PerfmonService perfmon = new PerfmonService(3000);
        if(enableStat) {
            perfmon.start();
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }
        if(enableStat) {
            perfmon.stop();
        }
        long elapsedCpuTime = sunmx.getProcessCpuTime() - startCpuTime;

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L;
        int ioContention = 0;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
            ioContention += stats[i].iocontention;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000L;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + ((algo == ReplacementAlgorithm.NbGClock || algo == ReplacementAlgorithm.NbGClockK) ? ", counter type: "
                        + System.getProperty("xbird.counter", "striped")
                        : "")
                + " - "
                + filename
                + "] synchronization: "
                + (useRWlock ? "rwlock" : (lock == null ? "sync"
                        : ((lock instanceof NoopLock) ? "non-blocking" : "spinlock"))) + ", read: "
                + numOps + ", miss: " + cacheMisses + ", hit ratio: " + hitRatio + ", miss ratio: "
                + missRatio + ", io contention: " + ioContention);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec);
        System.err.println("Elapsed cpu time: " + DateTimeFormatter.formatNanoTime(elapsedCpuTime));
        System.err.flush();
View Full Code Here

            throws IOException, InterruptedException {
        final ConcurrentPluggableCache<Long, byte[]> cache = new ConcurrentPluggableCache<Long, byte[]>(capacity, ConcurrentCollectionProvider.<ICacheEntry<Long, byte[]>> createConcurrentMapLong(capacity));
        cache.setReplacementPolicy(ReplacementPolicySelector.<Long, byte[]> provide(capacity, algo));

        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength + ", pageSize: "
                + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];

        final ReadWriteLock rwlock = new FairReadWriteLock();//new ReentrantReadWriteLock();

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final int threadId = i;
            final Status stat = new Status();
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            if(useRWlock) {
                                runBenchmarkWithZipfDistributionReadWriteLock(rwlock, stat, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            } else {
                                runBenchmarkWithZipfDistributionSync(stat, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                            }
                        } else {
                            runBenchmarkWithZipfDistributionLock(stat, lock, pager, cache, capacity, round, percent, scanLength, dist[threadId]);
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L, execInterval = 0L, durationHold = 0L;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
            execInterval += stats[i].execInterval;
            durationHold += stats[i].durationHold;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000L;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + " - "
                + filename
                + "] synchronization: "
                + (lock == null ? (useRWlock ? "readWrite" : "sync")
                        : ((lock instanceof NoopLock) ? "non-blocking" : "spinlock")) + ", read: "
                + numOps + ", miss: " + cacheMisses + ", hit ratio: " + hitRatio + ", miss ratio: "
                + missRatio);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec + ", total execution interval(msec): " + execInterval
                + ", total duration hold(msec): " + durationHold);
        System.err.flush();
View Full Code Here

            default:
                throw new IllegalStateException("unexpected algorithm for here: " + algo);
        }

        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength + ", pageSize: "
                + pageSize);

        final FixedSegments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final int threadId = i;
            final Status stat = new Status();
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            runBenchmarkWithZipfDistributionLongHashSync(stat, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                        } else {
                            runBenchmarkWithZipfDistributionLongHashLock(stat, lock, pager, hash, capacity, round, percent, scanLength, dist[threadId]);
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + " longhash - "
                + filename
                + "] synchronization: "
                + (lock == null ? "sync" : ((lock instanceof NoopLock) ? "non-blocking"
                        : "spinlock")) + ", read: " + numOps + ", miss: " + cacheMisses
                + ", hit ratio: " + hitRatio + ", miss ratio: " + missRatio);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec);
        System.err.flush();

        pager.close();
View Full Code Here

        System.gc();
        runLzf(input);
    }

    private static void runPFOR(char[] input) {
        StopWatch sw1 = new StopWatch("PFOR [on demand] compress: ");
        byte[] compressed = PFOR.compress(input);
        System.out.println(sw1.toString());
        StopWatch sw2 = new StopWatch("PFOR decompress: ");
        char[] decompressed = PFOR.decompressAsChars(compressed);
        System.out.println(sw2);
        ArrayAssert.assertEquals(input, decompressed);
        float ratio = (float) compressed.length / (float) (input.length << 1);
        System.out.println("Original: " + input.length + ", Compressed: " + compressed.length
View Full Code Here

                + ", Compression ratio: " + Float.toString(ratio * 100.0f));
    }

    private static void runLzf(byte[] input) {
        LZFCodec codec = new LZFCodec();
        StopWatch sw1 = new StopWatch("LZF compress: ");
        byte[] compressed = codec.compress(input);
        System.out.println(sw1.toString());
        StopWatch sw2 = new StopWatch("LZF decompress: ");
        byte[] decompressed = codec.decompress(compressed);
        System.out.println(sw2);
        ArrayAssert.assertEquals(input, decompressed);
        float ratio = (float) compressed.length / (float) input.length;
        System.out.println("Original: " + input.length + ", Compressed: " + compressed.length
View Full Code Here

        OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean();
        final com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx;
        long startCpuTime = sunmx.getProcessCpuTime();

        final double percent = scanPercentage / 100d;
        StopWatch watchdog = new StopWatch("nthreads: " + threads + ", capacity: " + capacity
                + ", scanPercentage: " + percent + ", scanLength: " + scanLength + ", pageSize: "
                + pageSize);

        final Segments pager = makeTempSegments(pageSize);
        final Status[] stats = new Status[threads];
        final ReadWriteLock rwlock = new ReentrantReadWriteLock();

        final boolean isGCLOCK = (algo == ReplacementAlgorithm.GClock);

        _start = _stop = false;
        final Thread[] thrs = new Thread[threads];
        for(int i = 0; i < threads; i++) {
            final Status stat = new Status();
            final int thrdnum = i;
            stats[i] = stat;
            thrs[i] = new Thread() {
                public void run() {
                    while(!_start) {
                        // Spin till Time To Go
                        try {
                            Thread.sleep(1);
                        } catch (Exception e) {
                        }
                    }
                    try {
                        if(lock == null) {
                            if(useRWlock) {
                                if(isGCLOCK) {
                                    runBenchmarkWithZipfDistributionReadWriteLockForGCLOCK(rwlock, thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                                } else {
                                    runBenchmarkWithZipfDistributionReadWriteLock(rwlock, thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                                }
                            } else {
                                runBenchmarkWithZipfDistributionSync(thrdnum, stat, pager, cache, capacity, round, percent, scanLength, dist);
                            }
                        } else {
                            if(isGCLOCK) {
                                runBenchmarkWithZipfDistributionLockForGCLOCK(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                            } else {
                                runBenchmarkWithZipfDistributionLock(thrdnum, stat, lock, pager, cache, capacity, round, percent, scanLength, dist);
                            }
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            };
        }
        PerfmonService perfmon = new PerfmonService(3000);
        if(enableStat) {
            perfmon.start();
        }
        // Run threads
        for(int i = 0; i < threads; i++) {
            thrs[i].start();
        }
        _start = true;
        try {
            Thread.sleep(TIME_TO_EST);
        } catch (InterruptedException e) {
        }
        _stop = true;
        for(int i = 0; i < threads; i++) {
            thrs[i].join();
        }
        if(enableStat) {
            perfmon.stop();
        }
        long elapsedCpuTime = sunmx.getProcessCpuTime() - startCpuTime;

        long numOps = 0L, cacheMisses = 0L, elapsed = 0L;
        int ioContention = 0;
        for(int i = 0; i < threads; i++) {
            numOps += stats[i].ops;
            cacheMisses += stats[i].miss;
            elapsed += stats[i].mills;
            ioContention += stats[i].iocontention;
        }
        long avgElapsedInSec = (elapsed / threads) / 1000L;
        long opsPerSec = numOps / avgElapsedInSec;

        long hit = numOps - cacheMisses;
        double hitRatio = ((double) hit) / numOps;
        double missRatio = ((double) cacheMisses) / numOps;
        System.err.println("["
                + algo
                + ((algo == ReplacementAlgorithm.NbGClock || algo == ReplacementAlgorithm.NbGClockK) ? ", counter type: "
                        + System.getProperty("xbird.counter", "striped")
                        : "")
                + " - "
                + filename
                + "] synchronization: "
                + (useRWlock ? "rwlock" : (lock == null ? "sync"
                        : ((lock instanceof NoopLock) ? "non-blocking" : "spinlock"))) + ", read: "
                + numOps + ", miss: " + cacheMisses + ", hit ratio: " + hitRatio + ", miss ratio: "
                + missRatio + ", io contention: " + ioContention);
        System.err.println(watchdog.toString());
        System.err.println("number of ops: " + numOps + ", average number of ops per second: "
                + opsPerSec);
        System.err.println("Elapsed cpu time: " + DateTimeFormatter.formatNanoTime(elapsedCpuTime));
        System.err.flush();
View Full Code Here

            }
        }
    }

    private void execute(Reader reader, int timeout) throws XQueryException {
        final StopWatch sw = new StopWatch("elapsed time");
        if(_perfmon) {
            try {
                new PerfmonService().start();
            } catch (ServiceException e) {
                System.err.println(PrintUtils.prettyPrintStackTrace(e));
            }
        }
        if(timeout > 0) {
            TimerTask cancel = new TimerTask() {
                public void run() {
                    System.err.println("Execution Timeout: " + sw.toString());
                    System.exit(1);
                }
            };
            Timer timer = new Timer();
            timer.schedule(cancel, timeout * 1000);
            try {
                execute(reader);
            } catch (XQueryException e) {
                timer.cancel();
                throw e;
            }
            timer.cancel();
        } else {
            execute(reader);
        }
        if(_timing) {
            if(_timing_in_msec) {
                System.out.println('\n' + sw.elapsed() + " msec");
            } else {
                System.out.println();
                System.out.println(sw);
            }
        }
View Full Code Here

            throws XQueryException {
        SAXWriter saxwr = prepareSAXWriter(writer);
        Serializer ser = new SAXSerializer(saxwr, writer);
        Sequence<? extends Item> result = proc.execute(module);
        if(_timing) {
            final StopWatch sw = new StopWatch("print time");
            ser.emit(result);
            if(_timing_in_msec) {
                System.out.println('\n' + sw.elapsed() + " msec");
            } else {
                System.out.println();
                System.out.println(sw);
            }
        } else {
View Full Code Here

TOP

Related Classes of xbird.util.datetime.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.