⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hammerfastcache.java

📁 一个自然语言处理的Java开源工具包。LingPipe目前已有很丰富的功能
💻 JAVA
字号:
package com.aliasi.test.unit.util;import com.aliasi.util.FastCache;import com.aliasi.util.Strings;import java.util.Map;import java.util.Random;public class HammerFastCache {    static final Random RANDOM = new Random();    static final long NUM_TESTS = 100000000000L;    static final int DIMENSIONS = 40;    static double sNextVal = 0.0;    static long sElapsedSum = 0;    static long sStartTime;    public static void main(String[] args) {        sStartTime = System.currentTimeMillis();        System.out.println("\nFastCache");        hammer(new FastCache<String,double[]>(100000));        // System.out.println("\nHardFastCache");        // hammer(new com.aliasi.util.HardFastCache<String,double[]>(100000));            }    static void hammer(Map<String,double[]> cache) {        long start = System.currentTimeMillis();        for (long i = 1; i <= NUM_TESTS; ++i) {            String s = nextString();            double[] a = nextArray();            cache.put(s,a);            long current = System.currentTimeMillis();            long elapsed = current - start;            start = current;            sElapsedSum += elapsed;            double avg = sElapsedSum / (double) i;            if (elapsed > 100 || (i % 10000000) == 0)                 System.out.println(i + " t=" + elapsed + "ms" + " avg=" + avg + "ms"                                   + " total time=" + Strings.msToString(current - sStartTime));            // if ((i % 100000) == 0)            // System.out.println(i + " avg=" + avg + "ms");        }    }    static String nextString() {        char[] cs = new char[RANDOM.nextBoolean()                             ? 1                             : ( RANDOM.nextBoolean()                                 ? 2                                 : ( RANDOM.nextBoolean()                                     ? 3                                     : ( RANDOM.nextBoolean()                                         ? 4                                         : RANDOM.nextBoolean()                                         ? 5                                         : 6 )))];        for (int i = 0; i < cs.length; ++i)            cs[i] = (char) RANDOM.nextInt(128);        return new String(cs);    }    static double[] nextArray() {        double[] result = new double[DIMENSIONS];        for (int i = 0; i < result.length; ++i) {            result[i] = sNextVal;            sNextVal += 0.0001;        }        return result;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -