Java Code Examples for com.google.common.math.LongMath#divide()
The following examples show how to use
com.google.common.math.LongMath#divide() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemoryBenchmark.java From caffeine with Apache License 2.0 | 6 votes |
private String[] evaluate(String label, Map<Integer, Integer> map) { long base = meter.measureDeep(map); map.putAll(workingSet); long populated = meter.measureDeep(map); long entryOverhead = 2 * FUZZY_SIZE * meter.measureDeep(workingSet.keySet().iterator().next()); long perEntry = LongMath.divide(populated - entryOverhead - base, FUZZY_SIZE, RoundingMode.HALF_EVEN); perEntry += ((perEntry & 1) == 0) ? 0 : 1; long aligned = ((perEntry % 8) == 0) ? perEntry : ((1 + perEntry / 8) * 8); return new String[] { label, String.format("%,d bytes", base), String.format("%,d bytes (%,d aligned)", perEntry, aligned) }; }
Example 2
Source File: CurrentTimestampFunction.java From crate with Apache License 2.0 | 6 votes |
private static long applyPrecision(long millis, int precision) { int factor; switch (precision) { case 0: factor = 1000; break; case 1: factor = 100; break; case 2: factor = 10; break; case 3: return millis; default: throw new IllegalArgumentException("Precision must be between 0 and 3"); } return LongMath.divide(millis, factor, RoundingMode.DOWN) * factor; }
Example 3
Source File: TpsWorkbeanch.java From saluki with Apache License 2.0 | 5 votes |
public static void run() throws Exception { Job job = new JobDetail(); // 创建Job executorService = Executors.newFixedThreadPool(N_THRESHOLDS); // 新建固定大小线程的池子 for (int i = 0; i < N_THRESHOLDS; i++) { executorService.submit(new Worker(job)); // 提交线程到池子中 } // 还需要一个线程,用于周期检查执行时间是否到达 final ScheduledExecutorService scheduledExcutor = Executors.newSingleThreadScheduledExecutor(); scheduledExcutor.scheduleAtFixedRate(new Runnable() { public void run() { if (totalTime.decrementAndGet() == 0) { // 执行时间递减到0 runnning = false; // 告诉线程,时间到了,所有线程不再执行 scheduledExcutor.shutdownNow(); } } }, 1L, 1L, TimeUnit.SECONDS); // 主线程等到所有的线程都退出,则开始统计 countDownLatch.await(); long totalExeCount = totalExecCount.get(); System.out.println(N_THRESHOLDS + " 个线程," + TIME_THRESHOLDS + " 秒内总共执行的事物数量:" + totalExeCount); long tps = LongMath.divide(totalExeCount, TIME_THRESHOLDS, RoundingMode.HALF_EVEN); System.out.println("OKHttp执行的TPS: " + tps); executorService.shutdownNow(); // 关闭线程池 }
Example 4
Source File: CurrentTimestampFunction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Long evaluate(Input<Integer>... args) { long millis = DateTimeUtils.currentTimeMillis(); if (args.length == 1) { Integer precision = args[0].value(); if (precision == null) { throw new IllegalArgumentException(String.format(Locale.ENGLISH, "NULL precision not supported for %s", NAME)); } int factor; switch (precision) { case 0: factor = 1000; break; case 1: factor = 100; break; case 2: factor = 10; break; case 3: factor = 1; break; default: throw new IllegalArgumentException("Precision must be between 0 and 3"); } millis = LongMath.divide(millis, factor, RoundingMode.DOWN) * factor; } return millis; }
Example 5
Source File: GuavaLongMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenDivideTwoLongValues_shouldDivideThemAndReturnTheResultForCeilingRounding() { long result = LongMath.divide(10L, 3L, RoundingMode.CEILING); assertEquals(4L, result); }
Example 6
Source File: GuavaLongMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenDivideTwoLongValues_shouldDivideThemAndReturnTheResultForFloorRounding() { long result = LongMath.divide(10L, 3L, RoundingMode.FLOOR); assertEquals(3L, result); }
Example 7
Source File: GuavaLongMathUnitTest.java From tutorials with MIT License | 4 votes |
@Test(expected = ArithmeticException.class) public void whenDivideTwoLongValues_shouldThrowArithmeticExceptionIfRoundingNotDefinedButNecessary() { LongMath.divide(10L, 3L, RoundingMode.UNNECESSARY); }
Example 8
Source File: HeapDisk.java From jimfs with Apache License 2.0 | 4 votes |
/** Returns the nearest multiple of {@code blockSize} that is <= {@code size}. */ private static int toBlockCount(long size, int blockSize) { return (int) LongMath.divide(size, blockSize, RoundingMode.FLOOR); }
Example 9
Source File: MathUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 能控制rounding方向的long相除 * * jdk的'/'运算符,直接向下取整 */ public static long divide(long p, long q, RoundingMode mode) { return LongMath.divide(p, q, mode); }
Example 10
Source File: MathUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 能控制rounding方向的long相除 * * jdk的'/'运算符,直接向下取整 */ public static long divide(long p, long q, RoundingMode mode) { return LongMath.divide(p, q, mode); }
Example 11
Source File: MathUtil.java From j360-dubbo-app-all with Apache License 2.0 | 2 votes |
/** * 能控制rounding方向的相除 * * jdk的'/'运算符,直接向下取整 */ public static long divide(long p, long q, RoundingMode mode) { return LongMath.divide(p, q, mode); }