com.google.common.base.Stopwatch#reset ( )源码实例Demo

下面列出了com.google.common.base.Stopwatch#reset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: grpc-nebula-java   文件: FakeClockTest.java
@Test
public void testStopWatch() {
  FakeClock fakeClock = new FakeClock();
  Stopwatch stopwatch = fakeClock.getStopwatchSupplier().get();
  long expectedElapsedNanos = 0L;

  stopwatch.start();

  fakeClock.forwardNanos(100L);
  expectedElapsedNanos += 100L;
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  fakeClock.forwardTime(10L, TimeUnit.MINUTES);
  expectedElapsedNanos += TimeUnit.MINUTES.toNanos(10L);
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  stopwatch.stop();

  fakeClock.forwardNanos(1000L);
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  stopwatch.reset();

  expectedElapsedNanos = 0L;
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));
}
 
源代码2 项目: kylin-on-parquet-v2   文件: TrieDictionaryTest.java
private void testEnumeratorValues(String file) throws Exception {
    InputStream is = new FileInputStream(file);
    ArrayList<String> str = loadStrings(is);
    TrieDictionaryBuilder<String> b = newDictBuilder(str);
    TrieDictionary<String> dict = b.build(0);
    System.out.println("Dictionary size for file " + file + " is " + dict.getSize());

    Stopwatch sw = new Stopwatch();
    sw.start();
    List<String> values1 = dict.enumeratorValuesByParent();
    System.out.println("By iterating id visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms");
    sw.reset();
    sw.start();
    List<String> values2 = dict.enumeratorValues();
    System.out.println("By pre-order visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms");
    sw.stop();
    assertEquals(Sets.newHashSet(values1), Sets.newHashSet(values2));
}
 
源代码3 项目: kylin-on-parquet-v2   文件: CuboidUtilTest.java
@Test
public void testGetLongestDepth() {
    Stopwatch sw = new Stopwatch();

    Set<Long> cuboidSet1 = Sets.newHashSet(7L, 6L, 5L, 4L, 3L, 2L, 1L);
    sw.start();
    assertEquals(2, CuboidUtil.getLongestDepth(cuboidSet1));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    Set<Long> cuboidSet2 = Sets.newHashSet(1024L, 1666L, 1667L, 1728L, 1730L, 1731L, 1760L, 1762L, 1763L, 1776L,
            1778L, 1779L, 1784L, 1788L, 1790L, 1791L, 1920L, 1922L, 1923L, 1984L, 1986L, 1987L, 2016L, 2018L, 2019L,
            2032L, 2034L, 2035L, 2040L, 2044L, 2046L, 2047L);
    sw.reset();
    sw.start();
    assertEquals(8, CuboidUtil.getLongestDepth(cuboidSet2));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    Set<Long> cuboidSet3 = Sets.newHashSet(31L, 11L, 5L, 3L, 1L);
    sw.reset();
    sw.start();
    assertEquals(3, CuboidUtil.getLongestDepth(cuboidSet3));
    System.out.println("Time cost for GetLongestDepth: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms");

    sw.stop();
}
 
源代码4 项目: tablesaw   文件: CsvReadPerformanceTest.java
/** Usage example using a Tornado data set */
public static void main(String[] args) throws Exception {

  Stopwatch stopwatch = Stopwatch.createStarted();
  Table details = Table.read().csv("../data/SHR76_16.csv");
  stopwatch.stop();
  System.out.println(
      "Large file (752,313 rows) read: "
          + stopwatch.elapsed(TimeUnit.MILLISECONDS)
          + " ms with type detection.");
  System.out.println(details.shape());
  System.out.println(details.structure().printAll());
  System.out.println(details);

  stopwatch.reset();
  stopwatch.start();
  details =
      Table.read().csv(CsvReadOptions.builder("../data/SHR76_16.csv").columnTypes(types).build());
  stopwatch.stop();

  System.out.println(
      "Large file (752,313 rows) read: "
          + stopwatch.elapsed(TimeUnit.MILLISECONDS)
          + " ms without type detection.");
  System.out.println(details.shape());
}
 
源代码5 项目: grpc-java   文件: FakeClockTest.java
@Test
public void testStopWatch() {
  FakeClock fakeClock = new FakeClock();
  Stopwatch stopwatch = fakeClock.getStopwatchSupplier().get();
  long expectedElapsedNanos = 0L;

  stopwatch.start();

  fakeClock.forwardNanos(100L);
  expectedElapsedNanos += 100L;
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  fakeClock.forwardTime(10L, TimeUnit.MINUTES);
  expectedElapsedNanos += TimeUnit.MINUTES.toNanos(10L);
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  stopwatch.stop();

  fakeClock.forwardNanos(1000L);
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));

  stopwatch.reset();

  expectedElapsedNanos = 0L;
  assertEquals(expectedElapsedNanos, stopwatch.elapsed(TimeUnit.NANOSECONDS));
}
 
protected void doTestWithStore(PersistenceObjectStore objectStore) {
    log.info("testing against "+objectStore.getSummaryName());
    
    objectStore.createSubPath("foo");
    StoreObjectAccessor f = objectStore.newAccessor("foo/file1.txt");
    Assert.assertFalse(f.exists());

    Stopwatch timer = Stopwatch.createStarted();
    f.append("Hello world");
    log.info("created in "+Duration.of(timer));
    timer.reset();
    Assert.assertEquals(f.get(), "Hello world");
    log.info("retrieved in "+Duration.of(timer));
    Assert.assertTrue(f.exists());
    
    timer.reset();
    List<String> files = objectStore.listContentsWithSubPath("foo");
    log.info("list retrieved in "+Duration.of(timer)+"; is: "+files);
    Assert.assertEquals(files, MutableList.of("foo/file1.txt"));
    
    f.delete();
}
 
源代码7 项目: meghanada-server   文件: ASMReflectorTest.java
@Test
public void testReflectWithGenerics2() throws Exception {
  ASMReflector asmReflector = ASMReflector.getInstance();
  Stopwatch stopwatch = Stopwatch.createUnstarted();
  {
    String fqcn = "java.util.Enumeration<? extends ZipEntry>";
    File jar = getRTJar();
    Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
    final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);

    stopwatch.start();
    List<MemberDescriptor> memberDescriptors = asmReflector.reflectAll(info);
    System.out.println(stopwatch.stop());
    memberDescriptors.forEach(m -> System.out.println(m.getDisplayDeclaration()));
    Config config = Config.load();
    if (config.isJava8()) {
      assertEquals(13, memberDescriptors.size());
    } else {
      assertEquals(14, memberDescriptors.size());
    }
    stopwatch.reset();
  }
}
 
源代码8 项目: TagRec   文件: CFResourceCalculator.java
private static List<Map<Integer, Double>> startBM25CreationForResourcesPrediction(BookmarkReader reader, int sampleSize, boolean userBased, boolean resBased, boolean allResources, boolean bll, Features features) {
	int size = reader.getBookmarks().size();
	int trainSize = size - sampleSize;
	
	Stopwatch timer = new Stopwatch();
	timer.start();		
	CFResourceCalculator calculator = new CFResourceCalculator(reader, trainSize, false, userBased, resBased, 5, Similarity.COSINE, features);
	timer.stop();
	long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
	
	timer.reset();
	timer.start();
	List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
	for (Integer userID : reader.getUniqueUserListFromTestSet(trainSize)) {
		Map<Integer, Double> map = null;
		map = calculator.getRankedResourcesList(userID, -1, true, allResources, bll, true, false); // TODO
		results.add(map);
	}
	timer.stop();
	long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
	
	timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime, sampleSize);
	return results;
}
 
源代码9 项目: meghanada-server   文件: ASMReflectorTest.java
@Test
public void testGetReflectClass2() throws Exception {
  ASMReflector asmReflector = ASMReflector.getInstance();
  Stopwatch stopwatch = Stopwatch.createUnstarted();
  {
    String fqcn = "java.util.stream.Stream";
    File jar = getRTJar();

    Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
    stopwatch.start();
    final InheritanceInfo info1 = asmReflector.getReflectInfo(index, fqcn);
    System.out.println(stopwatch.stop());
    System.out.println(info1);

    stopwatch.reset();
    stopwatch.start();
    final InheritanceInfo info2 = asmReflector.getReflectInfo(index, fqcn);
    System.out.println(stopwatch.stop());
    System.out.println(info2);
  }
}
 
源代码10 项目: meghanada-server   文件: ASMReflectorTest.java
@Test
public void testReflectInterface1() throws Exception {
  ASMReflector asmReflector = ASMReflector.getInstance();
  Stopwatch stopwatch = Stopwatch.createUnstarted();
  {
    String fqcn = "com.google.common.eventbus.SubscriberExceptionHandler";
    File jar = getJar("guava:guava:");
    Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
    final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);

    stopwatch.start();
    List<MemberDescriptor> memberDescriptors = asmReflector.reflectAll(info);
    System.out.println(stopwatch.stop());
    memberDescriptors.forEach(
        m -> {
          System.out.println(m.getDeclaration());
          System.out.println("Return: " + m.getRawReturnType());
        });
    assertEquals(1, memberDescriptors.size());
    stopwatch.reset();
  }
}
 
源代码11 项目: TagRec   文件: MPCalculator.java
private static List<int[]> getPopularTags(BookmarkReader reader, int sampleSize, int limit) {
	List<int[]> tags = new ArrayList<int[]>();
	Stopwatch timer = new Stopwatch();
	timer.start();

	int[] tagIDs = getPopularTagList(reader, limit);
	
	timer.stop();
	long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
	timer.reset();
	timer.start();
	for (int j = 0; j < sampleSize; j++) {
		tags.add(tagIDs);
	}
	timer.stop();
	long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
	
	timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime, sampleSize);
	return tags;
}
 
源代码12 项目: bboxdb   文件: TestFileIO.java
@Override
public void run() {
	final List<Integer> readBytesList = Arrays.asList(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384);
	final List<Integer> reads = Arrays.asList(1000000, 2500000, 5000000, 7500000, 10000000, 25000000, 50000000, 75000000, 100000000);

	try {
		generateTestData();

		for(final int readBytes : readBytesList) {
			System.out.println("Read requests\tTime random\tTime memory: " + readBytes);

			for(final int readRequsts : reads) {
				final Stopwatch stopwatch = Stopwatch.createStarted();

				for(int i = 0; i < RETRY; i++) {
					readDataRandom(readRequsts, readBytes);
				}

				final int timeRandom = (int) (stopwatch.elapsed(TimeUnit.MILLISECONDS) / RETRY);

				stopwatch.reset();
				stopwatch.start();

				for(int i = 0; i < RETRY; i++) {
					readDataMemoryMapped(readRequsts, readBytes);
				}

				final int timeMemory = (int) (stopwatch.elapsed(TimeUnit.MILLISECONDS) / RETRY);

				System.out.printf("%d\t%d\t%d%n", readRequsts, timeRandom, timeMemory);
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
private void tripleIngestBase(final BiConsumer<StandardJanusGraph, List<Triple>> writer) throws BackendException {
    final Stopwatch watch = Stopwatch.createStarted();
    final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open(TestGraphUtil.instance.createTestGraphConfig(BackendDataModel.MULTI));
    log.info("Created graph in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    watch.reset();
    watch.start();
    createHotelSchema(graph);
    log.info("Created schema in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");

    watch.reset();
    watch.start();
    final URL url = ScenarioTests.class.getClassLoader().getResource("META-INF/HotelTriples.txt");
    Preconditions.checkNotNull(url);
    final List<Triple> lines;
    try (CSVReader reader = new CSVReader(new InputStreamReader(url.openStream()))) {
        lines = reader.readAll().stream()
            .map(Triple::new)
            .collect(Collectors.toList());
    } catch (IOException e) {
        throw new IllegalStateException("Error processing triple file", e);
    }
    log.info("Read file into Triple objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    watch.reset();
    watch.start();
    writer.accept(graph, lines);
    log.info("Added objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    TestGraphUtil.instance.cleanUpTables();
}
 
private void testSetting(Settings settings, int inputCount) {
    SortedMap<byte[], Object> map = new TreeMap<>(new Comparator<byte[]>() {
        @Override
        public int compare(byte[] o1, byte[] o2) {
            return Bytes.compareTo(o1, o2);
        }
    });

    final int reportInterval = inputCount / 10;
    final Stopwatch stopwatch = new Stopwatch();
    long estimateMillis = 0;
    long actualMillis = 0;

    System.out.println("Settings: " + settings);
    System.out.printf(Locale.ROOT, "%15s %15s %15s %15s %15s\n", "Size", "Estimate(bytes)", "Actual(bytes)",
            "Estimate(ms)", "Actual(ms)");

    for (int i = 0; i < inputCount; i++) {
        byte[] key = new byte[10];
        random.nextBytes(key);
        MeasureAggregator[] values = createAggrs(settings);
        map.put(key, values);

        if ((i + 1) % reportInterval == 0) {
            stopwatch.start();
            long estimateBytes = GTAggregateScanner.estimateSizeOfAggrCache(key, values, map.size());
            estimateMillis += stopwatch.elapsedMillis();
            stopwatch.reset();

            stopwatch.start();
            long actualBytes = meter.measureDeep(map);
            actualMillis += stopwatch.elapsedMillis();
            stopwatch.reset();

            System.out.printf(Locale.ROOT, "%,15d %,15d %,15d %,15d %,15d\n", map.size(), estimateBytes,
                    actualBytes, estimateMillis, actualMillis);
        }
    }
    System.out.println("---------------------------------------\n");

    map = null;
    System.gc();
}
 
源代码15 项目: dremio-oss   文件: QuerySubmitter.java
public int submitQuery(DremioClient client, String plan, String type, String format, int width) throws Exception {

    String[] queries;
    QueryType queryType;
    type = type.toLowerCase();
    switch (type) {
      case "sql":
        queryType = QueryType.SQL;
        queries = plan.trim().split(";");
        break;
      case "logical":
        queryType = QueryType.LOGICAL;
        queries = new String[]{ plan };
        break;
      case "physical":
        queryType = QueryType.PHYSICAL;
        queries = new String[]{ plan };
        break;
      default:
        System.out.println("Invalid query type: " + type);
        return -1;
    }

    Format outputFormat;
    format = format.toLowerCase();
    switch (format) {
      case "csv":
        outputFormat = Format.CSV;
        break;
      case "tsv":
        outputFormat = Format.TSV;
        break;
      case "table":
        outputFormat = Format.TABLE;
        break;
      default:
        System.out.println("Invalid format type: " + format);
        return -1;
    }
    Stopwatch watch = Stopwatch.createUnstarted();
    for (String query : queries) {
      AwaitableUserResultsListener listener =
          new AwaitableUserResultsListener(new PrintingResultsListener(client.getConfig(), outputFormat, width));
      watch.start();
      client.runQuery(queryType, query, listener);
      int rows = listener.await();
      System.out.println(String.format("%d record%s selected (%f seconds)", rows, rows > 1 ? "s" : "", (float) watch.elapsed(TimeUnit.MILLISECONDS) / (float) 1000));
      if (query != queries[queries.length - 1]) {
        System.out.println();
      }
      watch.stop();
      watch.reset();
    }
    return 0;

  }
 
源代码16 项目: SimpleTextSearch   文件: main.java
public static void main(String args[]) throws Exception {

        File fXmlFile = new File("/Users/brad/Downloads/gaming.stackexchange.com/Posts.xml");

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        org.w3c.dom.Document doc = dBuilder.parse(fXmlFile);

        doc.getDocumentElement().normalize();

        System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

        NodeList nList = doc.getElementsByTagName("row");

        List<Document> documentList = new ArrayList<>();
        Map<String, String> idToBody = new HashMap<>();

        for (int i = 0; i < nList.getLength(); i++) {

            Node n = nList.item(i);

            String body = n.getAttributes().getNamedItem("Body").toString();
            String id = n.getAttributes().getNamedItem("Id").toString();

            Document document = new Document(body, id);
            documentList.add(document);

            idToBody.put(id, body);
        }

        Stopwatch sw = Stopwatch.createUnstarted();
        sw.start();
        TextSearchIndex index = SearchIndexFactory.buildIndex(documentList);
        sw.stop();


        System.out.println("finished building index took " + sw.toString());
        System.out.println("num documents: " + index.numDocuments());
        System.out.println("num terms: " + index.termCount());

        Scanner scanner = new Scanner(System.in);

        String searchTerm = "";
        while (!searchTerm.equalsIgnoreCase("EXIT")) {
            System.out.print("Enter your search terms or type EXIT: ");

              searchTerm = scanner.nextLine();
            sw.reset();
            sw.start();
            SearchResultBatch batch = index.search(searchTerm, 3);
            sw.stop();

            System.out.println("printing results for term: " + searchTerm);
            for (SearchResult result : batch.getSearchResults()) {
                System.out.println("----------\n\n");
                System.out.println("score = " + result.getRelevanceScore());
                System.out.println(idToBody.get(result.getUniqueIdentifier().toString()));
            }

            System.out.println("finished searching took: " + sw.toString());
            System.out.println("num documents searched: " + batch.getStats().getDocumentsSearched());

        }

    }
 
源代码17 项目: TagRec   文件: BLLCalculator.java
private static List<Map<Integer, Double>> startActCreation(BookmarkReader reader, int sampleSize, boolean sorting, boolean userBased, boolean resBased, double dVal,
		int beta, CalculationType cType, Double lambda) {
	int size = reader.getBookmarks().size();
	int trainSize = size - sampleSize;
	
	Stopwatch timer = new Stopwatch();
	timer.start();
	BLLCalculator calculator = new BLLCalculator(reader, trainSize, dVal, beta, userBased, resBased, cType, lambda);
	timer.stop();
	long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
	List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
	if (trainSize == size) {
		trainSize = 0;
	}
	
	timer.reset();
	timer.start();
	// List<List<Bookmark>> userBookmarks = Utilities.getBookmarks(reader.getBookmarks().subList(0, trainSize), false); // only when using items from train-set
	for (int i = trainSize; i < size; i++) { // the test-set
		Bookmark data = reader.getBookmarks().get(i);
		int userID = data.getUserID();
		int resID = data.getResourceID();
		
		if (cType == CalculationType.MUSIC) {
			if (i > 0) {
				data = reader.getBookmarks().get(i - 1); // last item from test set
				//data = Utilities.getLastBookmarkOfUser(userBookmarks, userID); // last item of train-set
				if (data.getUserID() == userID) {
					resID = data.getResourceID();
				} else {
					resID = -1;
				}
			}
		}
		Map<Integer, Double> map = calculator.getRankedTagList(userID, resID, sorting, cType);
		results.add(map);
	}
	timer.stop();
	long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
	
	timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime, sampleSize);
	return results;
}
 
源代码18 项目: TagRec   文件: MalletCalculatorTweet.java
/**
 * Start the creation of LDA model.
 * @param reader
 * @param sampleSize
 * @param sorting
 * @param numTopics
 * @param userBased
 * @param resBased
 * @param topicCreation
 * @return
 */
private static List<Map<Integer, Double>> startLdaCreation(BookmarkReader reader, int sampleSize, boolean sorting, int numTopics, boolean userBased, boolean resBased, boolean topicCreation) {
    int size = reader.getBookmarks().size();
    int trainSize = size - sampleSize;
    //int oldTrainSize = trainSize;
    
    Stopwatch timer = new Stopwatch();
    timer.start();
    MalletCalculatorTweet userCalc = null;
    List<Map<Integer, Integer>> userMaps = null;
    
    // what is meant by the user based maps
    if (userBased) {
        userMaps = Utilities.getUserMaps(reader.getBookmarks().subList(0, trainSize));
        userCalc = new MalletCalculatorTweet(userMaps, numTopics);
        userCalc.predictValuesProbs(topicCreation);
        System.out.println("User-Training finished");
    }
    MalletCalculator resCalc = null;
    List<Map<Integer, Integer>> resMaps = null;
    
    // what is meant by the resource based maps
    if (resBased) {
        resMaps = Utilities.getResMaps(reader.getBookmarks().subList(0, trainSize));
        resCalc = new MalletCalculator(resMaps, numTopics);
        resCalc.predictValuesProbs(topicCreation);
        System.out.println("Res-Training finished");
    }
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    if (topicCreation) {
        trainSize = 0;
    }
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timer.reset();
    timer.start();
    int mpCount = 0;
    for (int i = trainSize; i < size; i++) { // the test set
        Bookmark data = reader.getBookmarks().get(i);
        int userID = data.getUserID();
        int resID = data.getResourceID();

        Map<Integer, Double> userPredMap = null;
        if (userCalc != null) {
            // create the user prediction map fopr the given user
            userPredMap = userCalc.getValueProbsForID(userID, topicCreation);
        }
        Map<Integer, Double> resPredMap = null;
        if (resCalc != null) {
            //if (i > oldTrainSize) {
            //  System.out.println("Test-Set");
            //}
            // if res specific lda call, the create resource specific map
            resPredMap = resCalc.getValueProbsForID(resID, topicCreation);
            if (topicCreation && resPredMap == null) {
                resPredMap = resCalc.getMostPopularTopics();
                mpCount++;
            }
        }
        
        // get ranked tag list for the current user
        Map<Integer, Double> map = getRankedTagList(reader, userPredMap, resPredMap, sorting);
        
        
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    
    timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime, (topicCreation ? size : sampleSize));
    System.out.println("MpCount: " + mpCount);
    return results;
}
 
源代码19 项目: macrobase   文件: ContextualOutlierDetector.java
/**
 * Walking up the lattice, construct the lattice node, when include those lattice nodes that contain at least one dense context
 *
 * @param latticeNodes
 * @param data
 * @return
 */
private List<LatticeNode> levelUpLattice(List<LatticeNode> latticeNodes, List<ContextualDatum> data) {
    //sort the subspaces by their dimensions
    Stopwatch sw = Stopwatch.createUnstarted();
    log.debug("\tSorting lattice nodes in level {} by their dimensions ", latticeNodes.get(0).dimensions.size());
    sw.start();
    List<LatticeNode> latticeNodeByDimensions = new ArrayList<>(latticeNodes);
    Collections.sort(latticeNodeByDimensions, new LatticeNode.DimensionComparator());
    sw.stop();
    long sortingTime = sw.elapsed(TimeUnit.MILLISECONDS);
    sw.reset();
    log.debug("\tDone Sorting lattice nodes in level {} by their dimensions (duration: {}ms)",
              latticeNodes.get(0).dimensions.size(), sortingTime);
    //find out dense candidate subspaces
    List<LatticeNode> result = new ArrayList<LatticeNode>();
    log.debug("\tJoining lattice nodes in level {} by their dimensions ", latticeNodes.get(0).dimensions.size());
    sw.start();
    int numLatticeNodeJoins = 0;
    int numDenseContexts = 0;
    for (int i = 0; i < latticeNodeByDimensions.size(); i++) {
        for (int j = i + 1; j < latticeNodeByDimensions.size(); j++) {
            LatticeNode s1 = latticeNodeByDimensions.get(i);
            LatticeNode s2 = latticeNodeByDimensions.get(j);
            LatticeNode joined = s1.join(s2, data, denseContextTau);
            if (joined != null) {
                numLatticeNodeJoins++;
                //only interested in nodes that have dense contexts
                if (joined.getDenseContexts().size() != 0) {
                    result.add(joined);
                    numDenseContexts += joined.getDenseContexts().size();
                }
            }
        }
    }
    sw.stop();
    long joiningTime = sw.elapsed(TimeUnit.MILLISECONDS);
    sw.reset();
    log.debug("\tDone Joining lattice nodes in level {} by their dimensions (duration: {}ms)",
              latticeNodes.get(0).dimensions.size(), joiningTime);
    log.debug("\tDone Joining lattice nodes in level {} by their dimensions,"
              + " there are {} joins and {} dense contexts (average duration per lattice node pair join: {}ms)",
              latticeNodes.get(0).dimensions.size(), numLatticeNodeJoins, numDenseContexts,
              (numLatticeNodeJoins == 0) ? 0 : joiningTime / numLatticeNodeJoins);
    return result;
}
 
源代码20 项目: cloud-bigtable-examples   文件: WritePerfTest.java
protected static void runMutationTests(Connection conn, TableName tableName, long rowCount,
    int valueSize) throws IOException {
  System.out.println("starting mutations");
  Stopwatch uberStopwatch = Stopwatch.createUnstarted();
  Stopwatch incrementalStopwatch = Stopwatch.createUnstarted();
  try (BufferedMutator mutator = conn.getBufferedMutator(tableName)) {
    // Use the same value over and over again. Creating new random data takes time. Don't count
    // creating a large array towards Bigtable performance
    byte[] value = Bytes.toBytes(RandomStringUtils.randomAlphanumeric(valueSize));
    incrementalStopwatch.start();
    for (long i = 1; i < 10; i++) {
      // The first few writes are slow.
      doPut(mutator, value);
    }
    mutator.flush();
    BigtableUtilities.printPerformance("starter batch", incrementalStopwatch, 10);

    uberStopwatch.reset();
    incrementalStopwatch.reset();
    uberStopwatch.start();
    incrementalStopwatch.start();
    for (int i = 0; i < rowCount - 10; i++) {
      doPut(mutator, value);
      if (i > 0 && i % PRINT_COUNT == 0) {
        BigtableUtilities.printPerformance("one batch", incrementalStopwatch, PRINT_COUNT);
        BigtableUtilities.printPerformance("average so far", uberStopwatch, i);
        incrementalStopwatch.reset();
        incrementalStopwatch.start();
      }
    }
    incrementalStopwatch.reset();
    incrementalStopwatch.start();
    System.out.println("Flushing");
    mutator.flush();
    System.out.println(String.format("Flush took %d ms.",
            incrementalStopwatch.elapsed(TimeUnit.MILLISECONDS)));
    BigtableUtilities.printPerformance("full batch", uberStopwatch, Math.toIntExact(rowCount));
  } catch (RetriesExhaustedWithDetailsException e) {
    logExceptions(e);
  }
}