- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这里有一个关于 fnmatch 相对于 pathinfo 的速度的小争论:how to check if file is php?
我并不完全相信,所以决定对这两个函数进行基准测试。
使用动态和静态路径显示 pathinfo 更快。
我的基准测试逻辑和结论是否有效?
EDIT: Using mac php from cmd
PHP 5.3.0 (cli) (built: Jul 20 200913:56:33) Copyright (c) 1997-2009 ThePHP Group Zend Engine v2.3.0,Copyright (c) 1998-2009 ZendTechnologies
dynamic path pathinfo 3.2973630428314fnmatch 3.4520659446716 x1.05
static path pathinfo 0.86487698554993fnmatch 1.0420439243317 x1.2
mac xampp php from cmd
PHP 5.3.1 (cli) (built: Feb 27 201012:41:51) Copyright (c) 1997-2009 ThePHP Group Zend Engine v2.3.0,Copyright (c) 1998-2009 ZendTechnologies
dynamic path pathinfo 3.63922715187fnmatch 4.99041700363 x1.37
static path pathinfo 1.03110480309fnmatch 2.38929820061 x2.32
我在我的机器上包含了一个以秒为单位的 100,000 次迭代的结果样本:
dynamic path
pathinfo 3.79311800003
fnmatch 5.10071492195
x1.34
static path
pathinfo 1.03921294212
fnmatch 2.37709188461
x2.29
代码:
<pre>
<?php
$iterations=100000;
// Benchmark with dynamic file path
print("dynamic path\n");
$i=$iterations;
$t1=microtime(true);
while($i-->0){
$f='/'.uniqid().'/'.uniqid().'/'.uniqid().'/'.uniqid().'.php';
if(pathinfo($f,PATHINFO_EXTENSION)=='php') $d=uniqid();
}
$t2=microtime(true) - $t1;
print("pathinfo $t2\n");
$i=$iterations;
$t1=microtime(true);
while($i-->0){
$f='/'.uniqid().'/'.uniqid().'/'.uniqid().'/'.uniqid().'.php';
if(fnmatch('*.php',$f)) $d=uniqid();
}
$t3 = microtime(true) - $t1;
print("fnmatch $t3\n");
print('x'.round($t3/$t2,2)."\n\n");
// Benchmark with static file path
print("static path\n");
$f='/'.uniqid().'/'.uniqid().'/'.uniqid().'/'.uniqid().'.php';
$i=$iterations;
$t1=microtime(true);
while($i-->0) if(pathinfo($f,PATHINFO_EXTENSION)=='php') $d=uniqid();
$t2=microtime(true) - $t1;
print("pathinfo $t2\n");
$i=$iterations;
$t1=microtime(true);
while($i-->0) if(fnmatch('*.php',$f)) $d=uniqid();
$t3=microtime(true) - $t1;
print("fnmatch $t3\n");
print('x'.round($t3/$t2,2)."\n\n");
?>
</pre>
最佳答案
我的结果和你的相反:
php -f 2693428.php
dynamic path
pathinfo 4.5834331512451
fnmatch 3.2174317836761
x0.7
static path
pathinfo 2.1787130832672
fnmatch 0.95714497566223
x0.44
版本
PHP 5.3.0 (cli) (built: Jun 29 2009 21:25:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
关于php - 路径信息与 fnmatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2693428/
所以我有一个os.walk代码 search = self.search.get_text() top = '/home/bludiescript/tv-shows' for dirpath, dir
我正在尝试匹配一个模式,但一直失败(返回 1): fnmatch(findme, d_name, FNM_PATHNAME) 当 findme= "cproject", d_name="./.cpro
这里是Python初学者,我快疯了..我开始编写一个脚本,首先搜索 .edl,删除必要的数据并将结果保存到列表中。 完成后,我需要脚本创建一个新列表,其中包含我正在查找的文件的所有绝对路径,但它只继续
我正在尝试使用 fnmatch 过滤器来查找给定模式的文件。但是,如果我的模式类似于 subdir/t*.txt 我的代码 for path, subdirs, files in os.walk(ro
我有一个任务,我想检查目录中是否存在特殊文件 *.part。如果文件存在则再次检查,如果不存在,则打印“文件已删除”。 我使用 os.listdir(),接下来对于 lisdir 中的每个文件,我使用
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
这里有一个关于 fnmatch 相对于 pathinfo 的速度的小争论:how to check if file is php? 我并不完全相信,所以决定对这两个函数进行基准测试。 使用动态和静态路
我对 Python 比较陌生,如果我不了解任何术语或提出愚蠢的问题,那么抱歉。我的目标是将包含字符串“&”的特定目录中的任何文件名重命名为“x”。 到目前为止,我已经尝试让 python 查找这些文件
我正在尝试获取特定目录(及其子目录)中具有特定格式的所有文件。 我找到了一个可以帮助我的代码here ,如下所示: from fnmatch import fnmatch import os, os.
我们可以将 fnmatch 与两个正则表达式一起使用吗? 例如,如果我使用fnmatch("file*", "*", 0),在这种情况下它会匹配吗? 最佳答案 For example, if I us
我正在尝试使用 fnmatch 来匹配 Python 中的目录。但它不是只返回与模式匹配的目录,而是返回所有目录或不返回任何目录。 例如:F:\Downloads 有子目录\The Portland
我有一个包含以下格式文件的目录:LnLnnnnLnnn.txt 其中 L = 字母,n = 数字。例如:p2c0789c001.txt 我想根据第二个数字(即 0789)是否在特定的数字序列(例如 0
全新的 Python,来自 MATLAB。基本上没有 UNIX 或正则表达式知识。 我有一些要处理的数据分类到文件夹中。我想获取要处理的文件列表,因此我提示输入顶级文件夹并搜索该文件夹和子文件夹中的所
考虑这个模式:*.py。它匹配所有以 py 扩展名结尾的路径。现在,是否有可能找到一个匹配其他一切的模式? 我认为这样可以做到:*[!.][!p][!y],但显然 fnmatch.fnmatch总是返
以下代码未找到文件 patterns 中定义的任何模式。 #!/usr/bin/env python import os import fnmatch patternFile = open('patt
我有一系列具有命名模式的文件夹:%y-%m-%d我想使用 fnmatch 来查找它们并将它们附加到列表中。我目前正在使用此代码: for root, subs, files in os.wal
我正在使用递归 glob 查找文件并将其从一个驱动器复制到另一个 def recursive_glob(treeroot, pattern): results = [] for base,
我正在 Python 中创建一个循环,使用 fnmatch.filter() 运行特定目录中的所有文件。目前我正在浏览特定文件夹中的所有 .csv 文件,如下所示: for file_source i
我在 Linux 中有以下代码,用于查找与给定通配符匹配的文件: std::vector listFilenamesInPath(std::string wildcard = "*", std
在典型的文件匹配代码中: while (false !== ($file = readdir($handle))) { if ($file !== "." && $file !== ".."
我是一名优秀的程序员,十分优秀!