我调整了一个简单的程序来计算和绘制Julia的运动漩涡以测试语言,我也用Python编写它没有特别的原因.
(免责声明:1.我读过的stackoverflow的每一次性能比较都因为没有全面/正确/写得好/相关等等而受到抨击 - 我不是假装这是一个真正的比较,我只想知道如何制作朱莉娅更快.2.我知道python可以优化,在Cython等中实现,这不是讨论的一部分,它只是在这里为Julia和Python中的等效函数的参考.)
代码和性能结果可以在一个要点中看到.
Julia的表现明显慢于Fortran.执行计算所花费的时间是(50000个时间步长):
Fortran: 0.051s
Julia: 2.256s
Python: 30.846s
Run Code Online (Sandbox Code Playgroud)
朱莉娅比Fortran慢得多(慢44倍),差距缩小但仍然显着,时间步长增加10倍(0.50s vs 15.24s
).
这些结果与julia主页上显示的结果有很大不同.我究竟做错了什么?我可以修快朱莉娅吗?
我在Julia主页上浏览了Julia Performance Tips页面和比较背后的代码,没有什么能让我解决.
同样有趣的是,Julia加载PyPlot(5secs
ish !!)非常慢,而且比Python读取文本文件要慢得多.我可以做些什么来改善这些事情吗?
请注意,上面的时间不显示Julia和Python的加载时间,它只是计算AFAIK所需的原始时间 - 请参阅代码.对于fortran来说,这就是整个事情.在每种情况下,绘图都已大致关闭以允许速度比较.
计算机:Intel i7-3770,16GB RAM,SSD HD,操作系统:Ubuntu 13.10 64bit.,Fortran:gfortran,GNU Fortran(Ubuntu/Linaro 4.8.1-10ubuntu9)4.8.1,Julia:版本0.3.0-prerelease + 396 (2013-12-12 00:18 UTC),提交c5364db*(0天大师),x86_64-linux-gnu,Python:2.7.5+
根据ivarne的建议,我重新编写了Julia脚本(在上面的gist中更新):在函数中封装grunt工作,声明所有内容的类型,并在适用的情况下将矩阵的不同元素拆分为不同的数组.(我在很多地方都包含了Float64,因为我尝试了Float32,看看是否有帮助,但大部分时间都没有).
结果如下:
50,000
时间步骤:
Fortran: 0.051s (entire programme)
Julia: raw calc.: 0.201s, calc. and return (?): 0.758s, total exec.: 6.947s
Run Code Online (Sandbox Code Playgroud)
500,000
时间步骤:
Fortran: 0.495s (entire programme)
Julia: raw calc.: 1.547s, …
Run Code Online (Sandbox Code Playgroud) 这似乎是一个非常简单的问题,但是它让我绕过弯道.我确定它应该由RTFM解决,但我已经看了选项,我可以看到一个修复它.
我只想打印所有列的dtypes,目前我得到:
print df.dtypes
#>
Date object
Selection object
Result object
...
profit float64
PL float64
cumPL float64
Length: 11, dtype: object
Run Code Online (Sandbox Code Playgroud)
我试过设置选项display.max_row
,display.max_info_row
,display.max_info_columns
都无济于事.
我究竟做错了什么?
熊猫版= 0.13.1
更新:
事实证明,我是一个白痴,并没有display.max_row
达到足够高的价值.
解决方案是:
pd.set_option('display.max_rows', 20)
Run Code Online (Sandbox Code Playgroud) Django 1.8 将带有新的高级字段类型,包括依赖于PostgreSQL的ArrayField,并在数据库级别实现.
PostgreSQL的数组字段实现了一个append方法.
但是,我找不到任何关于附加项目的文档ArrayField
.这显然非常有用,因为它允许更新字段而不将其全部内容从数据库转移回数据库.
这可能吗?如果不是将来可能的话?任何指向我错过的文档的指针都将非常感激.
为了澄清我的要求,这将是伟大的:
注意:这是幻想代码,我认为不会工作(我没试过)
# on model:
class Post(models.Model):
tags = ArrayField(models.CharField(max_length=200))
# somewhere else:
p = Post.objects.create(tags=[str(i) for i in range(10000)])
p.tags.append('hello')
Run Code Online (Sandbox Code Playgroud)
目前有没有办法做到这一点,而不诉诸原始的SQL?
我将 pydanticBaseModel
与这样的验证器一起使用:
from datetime import date
from typing import List, Optional
from pydantic import BaseModel, BaseConfig, validator
class Model(BaseModel):
class Config(BaseConfig):
allow_population_by_alias = True
fields = {
"some_date": {
"alias": "some_list"
}
}
some_date: Optional[date]
some_list: List[date]
@validator("some_date", pre=True, always=True)
def validate_date(cls, value):
if len(value) < 2: # here value is some_list
return None
return value[0] # return the first value - let's assume it's a date string
# This reproduces the problem
m = Model(some_list=['2019-01-03'])
Run Code Online (Sandbox Code Playgroud)
我想some_date …
如何将Solid-JS 文档中的第一个示例转换为有效的打字稿?
import { render } from "solid-js/web"
const HelloMessage = props => <div>Hello {props.name}</div>
render(() => <HelloMessage name="Taylor" />, document.getElementById("hello-example"))
Run Code Online (Sandbox Code Playgroud)
我收到一个关于props
没有类型提示的错误,特别是Parameter 'props' implicitly has an 'any' type.
对于 React,我会使用React.FC
,但我找不到 Solid-JS 的等效项。
所以我构建了我希望成为一个简单的安卓游戏.我首先构建了一个网络版本以使其正常工作(http://scolvin.com/ballgame)然后将其移至PhoneGap并使用加速度计来控制游戏.唯一的问题(这是一个显示停止问题)是结果是可怕的慢(我估计每秒一次而不是20毫秒ish的更新).
这是没有当前解决方案的电话差距有多慢?或者是否有一些我失踪的金色子弹?
游戏使用easeljs和box2d-web.
奇怪的是它似乎在Android chrome上以合理的速度运行,但在android的"浏览器"(我似乎记得是基于firefox?)和在phonegap中的速度非常慢,可能使用相同的html渲染器/ js中断器.
我已经尝试过简化游戏,尽可能地摆脱游戏,使用setInterval
而不是accelerometer.watchAcceleration
全部无济于事.
我想知道从嵌套子类访问父变量的最佳方法是什么,目前我正在使用装饰器。
这是唯一/最好的方法吗???
我不想直接访问父变量(例如 ComponentModel.origin (见下文)),因为这将需要“配置”文件中的更多代码,所以我想知道是否可以在有问题的子类继承自哪个类?
我当前解决方案的简单示例:
# defined in a big library somewhere:
class LibrarySerialiser(object):
pass
# defined in my module:
class ModelBase:
pass
class SerialiserBase(LibrarySerialiser):
def __init__(self, *args, **kwargs):
# could i some how get hold of origin here without the decorator?
print self.origin
super(SerialiserBase, self).__init__(*args, **kwargs)
def setsubclasses(cls):
cls.Serialiser.origin = cls.origin
return cls
# written by "the user" for the particular application as the
# configuration of the module above:
@setsubclasses
class ComponentModel(ModelBase):
origin = 'supermarket'
class Serialiser(SerialiserBase): …
Run Code Online (Sandbox Code Playgroud) 我希望在请求期间执行的每个查询都有回溯,因此我可以找到它们的来源并减少计数/复杂性.
我正在使用这个优秀的中间件片段来列出和查询时间,但我不知道它们来自哪里.
我在django/db/models/sql/compiler.py中搜索过,但是明显的形式是获取本地版本的django并编辑该代码我无法看到如何锁定查询.有没有可以使用的信号?似乎每个查询都没有信号.
是否可以指定默认值Manager
?
(我知道django-toolbar,我希望有一个解决方案,而不使用它.)
如果用户(或机器人)重复做同样的事情,我希望recaptcha v3的得分会下降,但是事实并非如此。
这是从我的日志中摘录的摘要,而我在正在构建的网站上登录时尝试使用不同的密码。
2018-07-19T17:24:04.580129+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:08.764677+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:11.441256+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:14.697840+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:17.074292+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:19.477029+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:24:21.962033+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:25:14.458404+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:25:18.515887+00:00: grecaptcha success, score=0.900, action=login_password
2018-07-19T17:25:21.599782+00:00: grecaptcha success, score=0.900, action=login_password
Run Code Online (Sandbox Code Playgroud)
这是v3(测试版)中的问题吗?如果我尝试多次(数百次),分数会下降吗?还是给定会话的分数是恒定的,而不管用户的行为如何?
抱歉,如果这太过特定于产品,但是google似乎没有建议任何更好的地方来提出这样的问题,他们通常会建议这样做。
通读https://www.gstatic.com/recaptcha/api2/v1531759913576/recaptcha__en.js上的代码,有很多引用bottomleft
(bottomright
我认为与通常放置图标的位置相反)。
但是如何启用此设置并将图标移动到左下角?
我毫不怀疑在某处有答案,我就是找不到。
经过长时间的休息,我刚刚回到 c 并且非常生疏,所以请原谅愚蠢的错误。我需要生成一个大的(可能相当于 10mb)字符串。不知道要多久才能建成。
我尝试了以下两种方法来测试速度:
int main() {
#if 1
size_t message_len = 1; /* + 1 for terminating NULL */
char *buffer = (char*) malloc(message_len);
for (int i = 0; i < 200000; i++)
{
int size = snprintf(NULL, 0, "%d \n", i);
char * a = malloc(size + 1);
sprintf(a, "%d \n", i);
message_len += 1 + strlen(a); /* 1 + for separator ';' */
buffer = (char*) realloc(buffer, message_len);
strncat(buffer, a, message_len);
}
#else
FILE *f …
Run Code Online (Sandbox Code Playgroud) performance ×4
python ×4
django ×2
recaptcha ×2
recaptcha-v3 ×2
backtrace ×1
c ×1
captcha ×1
cordova ×1
django-1.8 ×1
django-orm ×1
fortran ×1
fortran77 ×1
html5 ×1
inheritance ×1
javascript ×1
jsx ×1
julia ×1
nested ×1
oop ×1
pandas ×1
postgresql ×1
pretty-print ×1
pydantic ×1
solid-js ×1
sql ×1
typescript ×1