V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
BacGa
V2EX  ›  程序员

Java 问题 [函数运行耗时] [文件流压缩]

  •  
  •   BacGa · 2020-01-04 10:57:21 +08:00 · 2288 次点击
    这是一个创建于 1567 天前的主题,其中的信息可能已经有所发展或是发生改变。

    1.对函数运行耗时计算,除了 long begin/end = System.nanoTime();这种方案 还有其他通用高效的轮子吗

    2.文件压缩能不能只经历 io 流的转换而不需生成中间文件落地,直接从 fileinputstream 转成 zipoutputstream

    9 条回复    2020-01-04 18:07:57 +08:00
    wysnylc
        1
    wysnylc  
       2020-01-04 13:32:00 +08:00
    1,获取当前执行时间已经是最简单的了,还要啥轮子?
    2,第二个我弄过类似的,文件流可以互相转换不需要写入磁盘
    BacGa
        2
    BacGa  
    OP
       2020-01-04 13:57:57 +08:00
    @wysnylc 大师兄 文件流的写法能给看看嘛
    wysnylc
        3
    wysnylc  
       2020-01-04 14:15:13 +08:00
    alvinbone88
        4
    alvinbone88  
       2020-01-04 14:42:19 +08:00 via Android
    第一个问题,Java Microbenchmark Harness
    luozic
        5
    luozic  
       2020-01-04 15:00:19 +08:00 via iPhone
    jmh 基于注解 可以写到测试类里面 通过命令跑。
    BacGa
        6
    BacGa  
    OP
       2020-01-04 15:02:19 +08:00
    @alvinbone88
    @luozic 感谢
    @wysnylc 师兄 图挂了 我 vx bacga_void_man :-)
    xiangyuecn
        7
    xiangyuecn  
       2020-01-04 15:26:28 +08:00
    不知道 ByteArrayInputStream ByteArrayOutputStream 有没有用,C#里面是 MemoryStream,反而觉得 Memory 比 ByteArray 好记
    guyeu
        8
    guyeu  
       2020-01-04 16:04:38 +08:00   ❤️ 1
    1. guava 有计时工具包 Stopwatch ;
    2. new ZipOutputStream(new FileOutputStream(out)),直接输出压缩文件,本来就不需要中间落一次地。
    itning
        9
    itning  
       2020-01-04 18:07:57 +08:00
    JMH 了解下
    ```xml
    <!-- JMH-->
    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-core</artifactId>
    <version>${jmh.version}</version>
    </dependency>
    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-generator-annprocess</artifactId>
    <version>${jmh.version}</version>
    <scope>provided</scope>
    </dependency>
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   922 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:44 · PVG 04:44 · LAX 13:44 · JFK 16:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.