RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
Harry
Asked: 2024-03-13 15:36:45 +0000 UTC

为什么 Windows 显示的正常运行时间比实际时间长?

  • 9

几天前,需要以编程方式确定一艘飞船的机器正常运行时间。嗯,问题很简单(GetTickCount[64]),但结果却很奇怪:虽然我早上打开了车,但很自信地得出正常运行时间超过一天的结论,表明昨天早上。我查看了任务管理器窗口中的相同值。

重新启动 - 一切正常,数据正确。但他开始追随。

连续几天,它都显示正常,在所有机器关闭的情况下都能正常工作。

昨晚,像往常一样,我通过“关机”关闭了机器。今天早上她告诉我——我从昨天早上就开始工作了!

会是什么呢?某种我没有要求的冬眠?我怎样才能确定?

windows
  • 1 个回答
  • 28 Views
Martin Hope
egor
Asked: 2024-03-05 23:02:16 +0000 UTC

请解释一下这个函数的作用是什么?它充当包装器吗?它是做什么用的?[复制]

  • 9
这个问题已经在这里得到回答:
JS 中的闭包语法 (3 个回答)
Javascript 中的语法含义是什么 ( function(){...} )( param1, param2); ?[重复] (6 个回答)
库的包装 (function(){})() (2 个答案)
17 小时前关闭。
(function(){
...(много других функций)
})();
javascript
  • 1 个回答
  • 39 Views
Martin Hope
Space Researcher
Asked: 2024-02-15 17:08:43 +0000 UTC

Python3和Golang在向2个文件写入数字的任务中速度的主观比较

  • 9

我用两种语言编写了相同的代码:

import os

file1 = open("z1.txt", "w")
file2 = open("z2.txt", "w")

for x in range(-1000, 1000):
    for y in range(-1000, 1000):
        z1 = (x + y) * (x + y)
        z2 = x * y

        args = str(x) + "\t" + str(y) + "\t"
        toFile1 = args + str(z1) + "\n"
        toFile2 = args + str(z2) + "\n"
        file1.write(toFile1)
        file2.write(toFile2)

file1.close()
file2.close()
package main

import (
  "os"
  "strconv"
)

func main() {
  file1, _ := os.Create("z1.txt")
  file2, _ := os.Create("z2.txt")
  for x := -1000; x < 1000; x++ {
    for y := -1000; y < 1000; y++ {
      z1 := (x + y) * (x + y)
      z2 := x * y

      args := strconv.Itoa(x) + "\t" + strconv.Itoa(y) + "\t"
      toFile1 := []byte(args + strconv.Itoa(z1) + "\n")
      toFile2 := []byte(args + strconv.Itoa(z2) + "\n")
      file1.Write(toFile1)
      file2.Write(toFile2)
    }
  }
  file1.Close()
  file2.Close()
}

一个意外的惊喜——在 golang 上,最坏情况下运行时间为 12 秒,而在 python 中则为 7 秒。在平均情况下,go 也远远落后,大约进行了 30 次运行。此外,golang 本身在该程序中以 2 个线程工作,这似乎可以加快写入两个文件的速度。

我怀疑我在 Go 中错误地使用了太低级的函数,并决定在 C 中实现相同的代码:

#include "stdio.h"

int main(){
    FILE* f1 = fopen("z1.txt","w");
    FILE* f2 = fopen("z2.txt","w");


    for (int x =-1000; x <1000;++x ){
        for(int y =-1000; y <1000;++y ){
            int z1 = (x+y)*(x+y);
            int z2 = x*y;

            fprintf(f1,"%d\t%d\t%d\n",x,y,z1);
            fprintf(f2,"%d\t%d\t%d\n",x,y,z2);
        }
    }
    fclose(f1);
    fclose(f2);

    return 0;
}

这里没有什么令人惊讶的——它会在瞬间完成所有事情。好吧,我尝试了 GoS 实现,它变得更糟 - 平均 22 秒。

package main

import (
    "fmt"
    "os"
)

func main() {
    file1, _ := os.Create("z1.txt")
    file2, _ := os.Create("z2.txt")

    for x := -1000; x < 1000; x++ {
        for y := -1000; y < 1000; y++ {
            z1 := (x + y) * (x + y)
            z2 := x * y

            fmt.Fprintf(file1, "%d\t%d\t%d\n", x, y, z1)
            fmt.Fprintf(file2, "%d\t%d\t%d\n", x, y, z2)
        }
    }
    file1.Close()
    file2.Close()
}

接下来,我尝试优化 Go 中的代码并写入文件 1 次,而不是循环写入,并将缓冲区存储在一行中,我在 Python 中做了同样的事情,但没有任何改变,我无法理解出了什么问题,为什么 golang 在这项任务上落后了。

带 Go 手写缓冲区的版本:

package main

import (
    "os"
    "strconv"
)

func main() {
    file1, _ := os.Create("z1.txt")
    file2, _ := os.Create("z2.txt")
    var toFile1 string
    var toFile2 string
    for x := -1000; x < 1000; x++ {
        for y := -1000; y < 1000; y++ {
            z1 := (x + y) * (x + y)
            z2 := x * y

            args := strconv.Itoa(x) + "\t" + strconv.Itoa(y) + "\t"
            toFile1 += (args + strconv.Itoa(z1) + "\n")
            toFile2 += (args + strconv.Itoa(z2) + "\n")

        }
    }

    file1.Write([]byte(toFile1))
    file2.Write([]byte(toFile2))

    file1.Close()
    file2.Close()
}

如果可能的话,请给出详细的答案,而不是“在go中还有一个额外的动作——转换为字节”。先感谢您)

python3 Python 3.10.12(主要,2023 年 11 月 20 日,15:14:05)[GCC 11.4.0] 在 Linux 上键入“help”、“copyright”、“credits”或“license”以获取更多信息。

go版本go1.21.6 linux/amd64

python
  • 1 个回答
  • 94 Views
Martin Hope
danielilinskii
Asked: 2024-01-31 16:00:17 +0000 UTC

可折叠立方体

  • 9

描述

大家好!我想制作一个立方体,当你将光标悬停在它上面时,它的边缘应该分开。您还需要在其边缘制作带有文本的箭头,当您悬停时,箭头应沿着其边缘移开,新文本将出现在下方。

.wrap {
  width: 1920px;
  position: relative;
  margin-top: 400px;
  perspective: 1000px;
  perspective-origin: 50% 50%;
}

.leg {
  position: relative;
  width: 0px;
  height: 100px;
  border: 1px solid black;
}

.fr,
.sc,
.th {
  position: relative;
}

.indicator {
  top: -85px;
  left: -170px;
  position: absolute;
}

.line {
  position: absolute;
  overflow: hidden;
  height: 300px;
  /* transform: rotate(45deg); */
}

.text {
  position: absolute;
  top: -120px;
  width: 100px;
}

.h-line {
  width: 100px;
  border: 1px solid black;
}

.d-line {
  margin-left: 86.5px;
  margin-top: 34px;
  width: 100px;
  border: 1px solid black;
  transform: rotate(45deg);
}

.cube {
  margin: auto;
  position: relative;
  height: 200px;
  width: 200px;
  transform-style: preserve-3d;
}

.cube>div {
  position: absolute;
  box-sizing: border-box;
  padding: 10px;
  height: 100%;
  width: 100%;
  opacity: 0.9;
  background-color: #000;
  border: solid 1px #eeeeee;
  color: #ff0000;
}

.legs {
  left: -65px;
  margin-top: 240px;
  position: absolute;
  display: flex;
  flex-direction: row;
  gap: 70px;
}

.sc {
  margin-left: 152px;
}

.th {
  margin-top: -78px;
}

.third {
  margin-top: 78px;
}

.front {
  transform: translateZ(100px);
}

.front--1 {
  transform: translateZ(100px);
}

.back {
  transform: translateZ(-100px) rotateY(180deg);
}

.right {
  transform: rotateY(-270deg) translateX(100px);
  transform-origin: top right;
}

.right--1 {
  transform: rotateY(-270deg) translateX(100px);
  transform-origin: top right;
}

.left {
  transform: rotateY(270deg) translateX(-100px);
  transform-origin: center left;
}

.top {
  transform: rotateX(-270deg) translateY(-100px);
  transform-origin: top center;
}

.top--1 {
  transform: rotateX(-270deg) translateY(-100px);
  transform-origin: top center;
}

.bottom {
  transform: rotateX(270deg) translateY(100px);
  transform-origin: bottom center;
}

.wrap:hover .front {
  transform: translateZ(200px) translateX(-200px);
  /*   margin-left: -200px;
    transition: 0.3s ease-in; */
  background-color: #fcf;
}

.wrap:hover .right {
  transform: rotateY(-270deg) translateZ(150px) translateX(150px);
}

.wrap:hover .top {
  transform: rotateX(-270deg) translateZ(120px) translateY(-100px);
}

.wrap:hover .bottom {
  transform: rotateX(270deg) translateZ(100px) translateY(100px);
}

.wrap:hover .legs {
  transform: translateY(100px);
  transition: transform 0.3s ease-in;
}

.wrap:not(:hover) .legs {
  transform: translateY(0);
  transition: transform 0.3s ease-in;
}

.wrap:hover .first {
  margin-top: 20px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .first {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .second {
  margin-top: 12px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .second {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .third {
  margin-top: -7px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .third {
  margin-top: 0;
  transition: 0.3s ease-in;
}

.wrap:hover .text {
  top: 5px;
  transition: 0.3s ease-in;
}

.wrap:not(:hover) .text {
  top: -120px;
  transition: 0.3s ease-in;
}

.cube>div {
  transition: transform 0.3s ease-in;
}

.cube {
  transform: rotateX(-15deg) rotateY(-25deg);
}
<div class="wrap">
  <div class="cube">
    <div class="front">
      <div class="indicator">
        1
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Front side
    </div>
    <div class="front--1">
      Front side
    </div>
    <div class="top">
      <div class="indicator">
        2
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Top side
    </div>
    <div class="top--1">
      Top side
    </div>
    <div class="bottom">
      <div class="indicator">
        3
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Bottom side
    </div>
    <div class="right">
      <div class="indicator">
        4
        <div class="line">
          <div class="h-line"></div>
          <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
        </div>
        <div class="d-line"></div>
      </div>
      Right side
    </div>

    <div class="right--1">
      Right side
    </div>
    <section class="legs">
      <div class="fr">
        <div class="first leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
      <div class="sc">
        <div class="second leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
      <div class="th">
        <div class="third leg"></div>
        <div class="indicator">
          4
          <div class="line">
            <div class="h-line"></div>
            <span class="text">текст текст текст текст текст текст текст текст текст текст текст текст</span>
          </div>
          <div class="d-line"></div>
        </div>
      </div>
    </section>
  </div>
</div>

问题

文本箭头不应与其所附着的立方体面位于同一平面,而应始终位于用户的正前方。
预先感谢您的合作!)

html
  • 1 个回答
  • 114 Views
Martin Hope
michk4
Asked: 2024-01-20 16:38:27 +0000 UTC

如何在不知道 C 宏中的类型的情况下输出 __VA_ARGS__

  • 9

如何在不知道宏参数类型的情况下使用 fprintf() 显示宏参数 __VA_ARGS__ 的值

#define LOG(M, ...) fprintf(stderr, "[INFO] %s [%d]: %s /*__VA_ARGS__?*/\n", __FILE__, __LINE__, M)
c
  • 5 个回答
  • 176 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5