dousha1873 2014-07-31 16:01
浏览 306
已采纳

在Go中,为什么“ File.Readdirnames”进行“ clock_gettime”系统调用?

As a follow up to this question, I am trying to write a Go program that only lists a files name in an efficient matter without unnecessary system calls. This is what I have thus far:

package main

import (
        "os"
        "fmt"
        "log"
)

func main() {

        // Open directory and check for errors
        f, err := os.Open(".")
        if err != nil {
                log.Fatal(err)
        }

        // Get file names
        files, err := f.Readdirnames(0)
        if err != nil {
                log.Fatal(err)
        }

        // Print files
        fmt.Print(files, "
")
}

However, when I run an strace, I see many of the following:

clock_gettime(CLOCK_REALTIME, {1406822401, 824793686}) = 0

What does that pertain to? How can I make this code more efficient?

  • 写回答

2条回答 默认 最新

  • doujing5435 2014-07-31 19:03
    关注

    I am spitballing, but I would think that it is related to Go's built-in scheduler and garbage collection.

    Short answer is, go will never be quite as fast as C because it provides all of that extra runtime functionality which C doesn't.

    The code you listed is probably the fastest way to do what you want in Go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line