ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/juli/TestOneLineFormatterPerformance.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/juli/TestOneLineFormatterPerformance.java
Status
scanned
Type
file
Name
TestOneLineFormatterPerformance.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
2809 (2.7 KB)
MD5
ce40eb9aba943d1990a1a4ec4e578330
SHA1
eb8d42194a67f9fe078a126ab6321115c0fe891f
SHA256
a30c0834218b4e1b33dd5f08ced8d5dd0f6871cadf0d1f761f8695d13fe18390
SHA512

      
    
SHA1_git
fca44f335055731a88058e73a8a8226d6c5279a8
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestOneLineFormatterPerformance.java | 2.7 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.juli; import org.junit.Assert; import org.junit.Test; /** * Compares date/time format implementations. The current implementation ({@link * DateFormatCache} is one to two orders of magnitude faster than * {@link String#format(String, Object...)} */ public class TestOneLineFormatterPerformance { @Test public void testDateFormat() throws Exception { DateFormat stringFormatImpl = new StringFormatImpl(); long stringFormatImplTime = doTestDateFormat(stringFormatImpl); DateFormat dateFormatCacheImpl = new DateFormatCacheImpl(); long dateFormatCacheImplTime = doTestDateFormat(dateFormatCacheImpl); Assert.assertTrue("String#format was faster that DateFormatCache", dateFormatCacheImplTime < stringFormatImplTime); } private long doTestDateFormat(DateFormat df) { int iters = 1000000; long start = System.nanoTime(); for (int i = 0; i < iters; i++) { df.format(System.nanoTime()); } long end = System.nanoTime(); System.out.println( "Impl: [" + df.getClass().getName() + "] took [" + (end - start) + "] ns"); return end - start; } private interface DateFormat { String format(long timestamp); } private static class StringFormatImpl implements DateFormat { @Override public String format(long timestamp) { return String.format("%1$td-%1$tb-%1$tY %1$tH:%1$tM:%1$tS", Long.valueOf(timestamp)); } } private static class DateFormatCacheImpl implements DateFormat { private final DateFormatCache cache; DateFormatCacheImpl() { cache = new DateFormatCache(5, "dd-MMM-yyyy HH:mm:ss", null); } @Override public String format(long timestamp) { return cache.getFormat(timestamp); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
40.34
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9