小编Joo*_*zty的帖子

我怎样才能加快这个循环?

如何加速此循环(在C中)?

unsigned int x = 50000000;
double a= 0.9;
double b= -0.9;
for ( unsigned int i = 1; i <= x; i++)
{
    a *= 0.9; //power
    b -=  a/i;
}
Run Code Online (Sandbox Code Playgroud)

执行时间:14.000秒

我不知道为什么,但是当我在代码中添加这两行时,执行时间只有1.000秒.

unsigned int x = 50000000;
double a= 0.9;
double b= -0.9;
for ( unsigned int i = 1; i <= x; i++)
{
    a *= 0.9; //power
    a += 10e250;
    a -=10e250;
    b -=  a/i;
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

c performance loops

6
推荐指数
1
解决办法
99
查看次数

Mac OS上的PHP 7.2 memcached扩展

我想在mac OS High Sierra上设置php memcached扩展.我正在运行php 7.2

php -v的输出:

PHP 7.2.6 (cli) (built: May 25 2018 06:18:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)

我安装了memcached,pecl没有任何错误:

pecl install memcached
Run Code Online (Sandbox Code Playgroud)

它在php.ini文件中启用:

extension="memcached.so"
Run Code Online (Sandbox Code Playgroud)

当我<?php echo phpinfo();?>在我的Apache服务器上运行时.我可以看到配置的会话:

session.save_handler    memcached   memcached
Run Code Online (Sandbox Code Playgroud)

我的symfony应用程序仍然给我这个错误:

(1/1) ClassNotFoundException
Attempted to load class "Memcached" from the global namespace.
Did you forget a "use" statement?
Run Code Online (Sandbox Code Playgroud)

编辑: …

php memcached symfony macos-sierra

5
推荐指数
1
解决办法
2444
查看次数

从 Typescript 中的 promise 推断返回值

我有一个非常简单的函数,它接受两个参数——节点对象异步函数,它们以某种方式处理给定的节点并返回处理过的节点,它可以是任何东西。

我想让它通用并从异步函数推断类型。这是我的尝试,但 TS 在抱怨,我真的不明白为什么。

// ensure that callback is of a correct type
type NodeCallback<H> = H extends (node: Node) => Promise<infer R> ? (node: Node) => Promise<R> : never

// retrieve return value
type NodeCallbackReturnValue<H> = H extends (node: Node) => Promise<infer R> ? R : never


const myAsyncFunction = <_, C>(node: Node, cb: NodeCallback<C>) => {
  return cb(node)
}


myAsyncFunction(document, (node: Node) => Promise.resolve(node.nodeType))
Run Code Online (Sandbox Code Playgroud)

游乐场在这里

typescript

5
推荐指数
1
解决办法
173
查看次数

symfony中的Autowire String参数

如何在Symfony 3.4中连接String参数?

我有简单的服务,我想连接一个url指定的参数parameters.yml:

namespace AppBundle\Service;

use Psr\Log\LoggerInterface;

class PythonService {

    private $logger;
    private $url;

    /**
     * @param LoggerInterface $logger
     * @param String $url
     */
    public function __construct(LoggerInterface $logger, String $url) {
        $this->logger = $logger;
        $this->url = $url;
    }
}
Run Code Online (Sandbox Code Playgroud)

service.yml看起来像:

AppBunde\Services\PythonService:
    arguments: ['@logger', '%url%']
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Cannot autowire service "AppBundle\Service\PythonService": argument "$url" of method "__construct()" is type-hinted "string", you should configure its value explicitly.
Run Code Online (Sandbox Code Playgroud)

我也试过手动指定参数:

AnalyticsDashboardBunde\Services\PythonService:
    arguments:
        $logger: '@logger'
        $url: '%session_memcached_host%'
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

Invalid service "AppBundle\Services\PythonService": …
Run Code Online (Sandbox Code Playgroud)

php symfony

3
推荐指数
1
解决办法
2532
查看次数

如何尝试运行 django 服务器

我正在尝试编写测试来测试 django 应用程序是否可运行。我只想尝试运行 django 服务器,如果一切正常,则返回代码 0,否则返回另一个代码。

python manage.py runserver
Run Code Online (Sandbox Code Playgroud)

该命令运行无限循环,我需要通过CTRL + C停止它。这就是问题所在。我想运行它几秒钟。

注意:我在 Linux 上运行 django。

python django

2
推荐指数
1
解决办法
566
查看次数

谷歌图表中的工具提示数字格式

如何在谷歌图表的工具提示中格式化数字?我尝试在数据表中应用"none"格式,并"####"在 google 图表选项中的 h 轴上应用格式,但仍然可以在工具提示中看到 2,012。

  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
            [
            {label: "year", type: "number", format: "none"},
            {label: "performance", type: "number", format: "none"},
        ],
        ["2009", 10],
        ["2010", 15],
        ["2011", 3],
        ["2012", 5]
    ]);

    var options = {
      title: 'Company Performance',
      hAxis: {title: 'Year',  titleTextStyle: {color: '#333'}, format: "####"},
      vAxis: {minValue: 0}
    };

    var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
    chart.draw(data, options);
  }
Run Code Online (Sandbox Code Playgroud)

JSFiddle 可以在这里找到:https ://jsfiddle.net/ux37j0dk/3/

charts google-visualization

2
推荐指数
1
解决办法
2923
查看次数

HTML 中的命名空间是什么?

我试图理解 HTML 中的命名空间非常简单。

使用这两个命令有什么区别。为什么要用createElementNSover createElement

const a = document.createElementNS("http://www.w3.org/2000/svg", "svg")
const b = document.createElement("svg")
Run Code Online (Sandbox Code Playgroud)

资源:

html javascript

2
推荐指数
1
解决办法
59
查看次数

encodings.utf_8.StreamReader readline(),read()和seek()不合作

考虑这个非常简单的例子.

import codecs
from io import BytesIO

string = b"""# test comment
Some line without comment
# another comment
"""

reader = codecs.getreader("UTF-8")
stream = reader(BytesIO(string))

lines = []
while True:
    # get current position
    position = stream.tell()

    # read first character
    char = stream.read(1)

    # return cursor to start
    stream.seek(position, 0)

    # end of stream
    if char == "":
        break

    # line is not comment
    if char != "#":
        lines.append(stream.readline())
        continue

    # line is comment. Skip it.
    stream.readline()

print(lines) …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

1
推荐指数
1
解决办法
283
查看次数

BytesIO -&gt; BufferedIOBase -&gt; TextIOWrapper 无法读取行

我正在尝试从像对象这样的字节中读取行。

这是一个非常简单的例子。我知道它可以以不同的方式完成,但保持这种流动很重要(BytesIO -> BufferedIOBase -> TextIOWrapper)。

import io
bytes_io = io.BytesIO(b"a\nb\nc")
buffered_io_base = io.BufferedIOBase(bytes_io)
text_io = io.TextIOWrapper(buffered_io_base)
for line in text_io:
    print(line)
Run Code Online (Sandbox Code Playgroud)

这最终会出现错误:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
io.UnsupportedOperation: not readable
Run Code Online (Sandbox Code Playgroud)

Python 版本 3.6.5

python io python-3.x

0
推荐指数
1
解决办法
1635
查看次数