Skip to content

Commit fe21bc4

Browse files
committed
copy find appr
1 parent f4817b9 commit fe21bc4

File tree

2 files changed

+128
-36
lines changed

2 files changed

+128
-36
lines changed

.ipynb_checkpoints/timeit_tests-checkpoint.ipynb

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:b8d5bf725bbe6b0e07d0b544cb5a65cdce7b4c162fd421985a4aa25ea57f9151"
4+
"signature": "sha256:9e62469f6250ac6d58e6d3d2c67a5995d1505778b147ae918d71f4ebc1c12fb6"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -1270,14 +1270,14 @@
12701270
"import subprocess\n",
12711271
"\n",
12721272
"def subprocess_findcopy(path, search_str, dest): \n",
1273-
" query = 'find %s -name \"%s\" -exec cp {}\" %s \\;' %(path, search_str, dest)\n",
1273+
" query = 'find %s -name \"%s\" -exec cp {} %s \\;' %(path, search_str, dest)\n",
12741274
" subprocess.call(query, shell=True)\n",
12751275
" return "
12761276
],
12771277
"language": "python",
12781278
"metadata": {},
12791279
"outputs": [],
1280-
"prompt_number": 2
1280+
"prompt_number": 30
12811281
},
12821282
{
12831283
"cell_type": "markdown",
@@ -1297,32 +1297,50 @@
12971297
"def walk_findcopy(path, search_str, dest):\n",
12981298
" for path, subdirs, files in os.walk(path):\n",
12991299
" for name in fnmatch.filter(files, search_str):\n",
1300-
" shutil.copy(os.path.join(path,name), dest)"
1300+
" try:\n",
1301+
" shutil.copy(os.path.join(path,name), dest)\n",
1302+
" except NameError:\n",
1303+
" pass\n",
1304+
" return"
13011305
],
13021306
"language": "python",
13031307
"metadata": {},
13041308
"outputs": [],
1305-
"prompt_number": 3
1309+
"prompt_number": 33
13061310
},
13071311
{
13081312
"cell_type": "code",
13091313
"collapsed": false,
13101314
"input": [
13111315
"import timeit\n",
13121316
"\n",
1317+
"\n",
1318+
"def findcopy_timeit(inpath, outpath, search_str):\n",
1319+
" \n",
1320+
" shutil.rmtree(outpath)\n",
1321+
" os.mkdir(outpath)\n",
1322+
" print(50*'#')\n",
1323+
" print('subprocsess call')\n",
1324+
" %timeit subprocess_findcopy(inpath, search_str, outpath)\n",
1325+
" print(\"copied %s files\" %len(os.listdir(outpath)))\n",
1326+
" shutil.rmtree(outpath)\n",
1327+
" os.mkdir(outpath)\n",
1328+
" print('\\nos.walk approach')\n",
1329+
" %timeit walk_findcopy(inpath, search_str, outpath)\n",
1330+
" print(\"copied %s files\" %len(os.listdir(outpath)))\n",
1331+
" print(50*'#')\n",
1332+
"\n",
13131333
"print('small tree')\n",
13141334
"inpath = '/Users/sebastian/Desktop/testdir_in'\n",
13151335
"outpath = '/Users/sebastian/Desktop/testdir_out'\n",
1316-
"searchstr = '*.png'\n",
1317-
"%timeit subprocess_findcopy(inpath, searchstr, outpath)\n",
1318-
"%timeit walk_findcopy(inpath, searchstr, outpath)\n",
1336+
"search_str = '*.png'\n",
1337+
"findcopy_timeit(inpath, outpath, search_str)\n",
13191338
"\n",
1320-
"print('\\nlarger tree')\n",
1339+
"print('larger tree')\n",
13211340
"inpath = '/Users/sebastian/Dropbox'\n",
13221341
"outpath = '/Users/sebastian/Desktop/testdir_out'\n",
1323-
"searchstr = '*.csv'\n",
1324-
"%timeit subprocess_findcopy(inpath, searchstr, outpath)\n",
1325-
"%timeit walk_findcopy(inpath, searchstr, outpath)"
1342+
"search_str = '*.csv'\n",
1343+
"findcopy_timeit(inpath, outpath, search_str)\n"
13261344
],
13271345
"language": "python",
13281346
"metadata": {},
@@ -1332,44 +1350,72 @@
13321350
"stream": "stdout",
13331351
"text": [
13341352
"small tree\n",
1335-
"100 loops, best of 3: 8.48 ms per loop"
1353+
"##################################################"
13361354
]
13371355
},
13381356
{
13391357
"output_type": "stream",
13401358
"stream": "stdout",
13411359
"text": [
13421360
"\n",
1343-
"100 loops, best of 3: 22.3 ms per loop"
1361+
"subprocsess call\n",
1362+
"1 loops, best of 3: 268 ms per loop"
13441363
]
13451364
},
13461365
{
13471366
"output_type": "stream",
13481367
"stream": "stdout",
13491368
"text": [
13501369
"\n",
1370+
"copied 13 files\n",
1371+
"\n",
1372+
"os.walk approach\n",
1373+
"100 loops, best of 3: 12.2 ms per loop"
1374+
]
1375+
},
1376+
{
1377+
"output_type": "stream",
1378+
"stream": "stdout",
1379+
"text": [
13511380
"\n",
1381+
"copied 13 files\n",
1382+
"##################################################\n",
13521383
"larger tree\n",
1353-
"10 loops, best of 3: 7.13 ms per loop"
1384+
"##################################################\n",
1385+
"subprocsess call\n",
1386+
"1 loops, best of 3: 623 ms per loop"
13541387
]
13551388
},
13561389
{
13571390
"output_type": "stream",
13581391
"stream": "stdout",
13591392
"text": [
13601393
"\n",
1361-
"1 loops, best of 3: 413 ms per loop"
1394+
"copied 105 files\n",
1395+
"\n",
1396+
"os.walk approach\n",
1397+
"1 loops, best of 3: 417 ms per loop"
13621398
]
13631399
},
13641400
{
13651401
"output_type": "stream",
13661402
"stream": "stdout",
13671403
"text": [
1368-
"\n"
1404+
"\n",
1405+
"copied 105 files\n",
1406+
"##################################################\n"
13691407
]
13701408
}
13711409
],
1372-
"prompt_number": 4
1410+
"prompt_number": 35
1411+
},
1412+
{
1413+
"cell_type": "code",
1414+
"collapsed": false,
1415+
"input": [],
1416+
"language": "python",
1417+
"metadata": {},
1418+
"outputs": []
13731419
},
13741420
{
13751421
"cell_type": "markdown",

benchmarks/timeit_tests.ipynb

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:b8d5bf725bbe6b0e07d0b544cb5a65cdce7b4c162fd421985a4aa25ea57f9151"
4+
"signature": "sha256:9e62469f6250ac6d58e6d3d2c67a5995d1505778b147ae918d71f4ebc1c12fb6"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -1270,14 +1270,14 @@
12701270
"import subprocess\n",
12711271
"\n",
12721272
"def subprocess_findcopy(path, search_str, dest): \n",
1273-
" query = 'find %s -name \"%s\" -exec cp {}\" %s \\;' %(path, search_str, dest)\n",
1273+
" query = 'find %s -name \"%s\" -exec cp {} %s \\;' %(path, search_str, dest)\n",
12741274
" subprocess.call(query, shell=True)\n",
12751275
" return "
12761276
],
12771277
"language": "python",
12781278
"metadata": {},
12791279
"outputs": [],
1280-
"prompt_number": 2
1280+
"prompt_number": 30
12811281
},
12821282
{
12831283
"cell_type": "markdown",
@@ -1297,32 +1297,50 @@
12971297
"def walk_findcopy(path, search_str, dest):\n",
12981298
" for path, subdirs, files in os.walk(path):\n",
12991299
" for name in fnmatch.filter(files, search_str):\n",
1300-
" shutil.copy(os.path.join(path,name), dest)"
1300+
" try:\n",
1301+
" shutil.copy(os.path.join(path,name), dest)\n",
1302+
" except NameError:\n",
1303+
" pass\n",
1304+
" return"
13011305
],
13021306
"language": "python",
13031307
"metadata": {},
13041308
"outputs": [],
1305-
"prompt_number": 3
1309+
"prompt_number": 33
13061310
},
13071311
{
13081312
"cell_type": "code",
13091313
"collapsed": false,
13101314
"input": [
13111315
"import timeit\n",
13121316
"\n",
1317+
"\n",
1318+
"def findcopy_timeit(inpath, outpath, search_str):\n",
1319+
" \n",
1320+
" shutil.rmtree(outpath)\n",
1321+
" os.mkdir(outpath)\n",
1322+
" print(50*'#')\n",
1323+
" print('subprocsess call')\n",
1324+
" %timeit subprocess_findcopy(inpath, search_str, outpath)\n",
1325+
" print(\"copied %s files\" %len(os.listdir(outpath)))\n",
1326+
" shutil.rmtree(outpath)\n",
1327+
" os.mkdir(outpath)\n",
1328+
" print('\\nos.walk approach')\n",
1329+
" %timeit walk_findcopy(inpath, search_str, outpath)\n",
1330+
" print(\"copied %s files\" %len(os.listdir(outpath)))\n",
1331+
" print(50*'#')\n",
1332+
"\n",
13131333
"print('small tree')\n",
13141334
"inpath = '/Users/sebastian/Desktop/testdir_in'\n",
13151335
"outpath = '/Users/sebastian/Desktop/testdir_out'\n",
1316-
"searchstr = '*.png'\n",
1317-
"%timeit subprocess_findcopy(inpath, searchstr, outpath)\n",
1318-
"%timeit walk_findcopy(inpath, searchstr, outpath)\n",
1336+
"search_str = '*.png'\n",
1337+
"findcopy_timeit(inpath, outpath, search_str)\n",
13191338
"\n",
1320-
"print('\\nlarger tree')\n",
1339+
"print('larger tree')\n",
13211340
"inpath = '/Users/sebastian/Dropbox'\n",
13221341
"outpath = '/Users/sebastian/Desktop/testdir_out'\n",
1323-
"searchstr = '*.csv'\n",
1324-
"%timeit subprocess_findcopy(inpath, searchstr, outpath)\n",
1325-
"%timeit walk_findcopy(inpath, searchstr, outpath)"
1342+
"search_str = '*.csv'\n",
1343+
"findcopy_timeit(inpath, outpath, search_str)\n"
13261344
],
13271345
"language": "python",
13281346
"metadata": {},
@@ -1332,44 +1350,72 @@
13321350
"stream": "stdout",
13331351
"text": [
13341352
"small tree\n",
1335-
"100 loops, best of 3: 8.48 ms per loop"
1353+
"##################################################"
13361354
]
13371355
},
13381356
{
13391357
"output_type": "stream",
13401358
"stream": "stdout",
13411359
"text": [
13421360
"\n",
1343-
"100 loops, best of 3: 22.3 ms per loop"
1361+
"subprocsess call\n",
1362+
"1 loops, best of 3: 268 ms per loop"
13441363
]
13451364
},
13461365
{
13471366
"output_type": "stream",
13481367
"stream": "stdout",
13491368
"text": [
13501369
"\n",
1370+
"copied 13 files\n",
1371+
"\n",
1372+
"os.walk approach\n",
1373+
"100 loops, best of 3: 12.2 ms per loop"
1374+
]
1375+
},
1376+
{
1377+
"output_type": "stream",
1378+
"stream": "stdout",
1379+
"text": [
13511380
"\n",
1381+
"copied 13 files\n",
1382+
"##################################################\n",
13521383
"larger tree\n",
1353-
"10 loops, best of 3: 7.13 ms per loop"
1384+
"##################################################\n",
1385+
"subprocsess call\n",
1386+
"1 loops, best of 3: 623 ms per loop"
13541387
]
13551388
},
13561389
{
13571390
"output_type": "stream",
13581391
"stream": "stdout",
13591392
"text": [
13601393
"\n",
1361-
"1 loops, best of 3: 413 ms per loop"
1394+
"copied 105 files\n",
1395+
"\n",
1396+
"os.walk approach\n",
1397+
"1 loops, best of 3: 417 ms per loop"
13621398
]
13631399
},
13641400
{
13651401
"output_type": "stream",
13661402
"stream": "stdout",
13671403
"text": [
1368-
"\n"
1404+
"\n",
1405+
"copied 105 files\n",
1406+
"##################################################\n"
13691407
]
13701408
}
13711409
],
1372-
"prompt_number": 4
1410+
"prompt_number": 35
1411+
},
1412+
{
1413+
"cell_type": "code",
1414+
"collapsed": false,
1415+
"input": [],
1416+
"language": "python",
1417+
"metadata": {},
1418+
"outputs": []
13731419
},
13741420
{
13751421
"cell_type": "markdown",

0 commit comments

Comments
 (0)