Using slices on hash variable :)
sub array_union { my ($arrRef1, $arrRef2) = @_; my %hash; @hash{@$arrRef1} = undef; @hash{@$arrRef2} = undef; return keys %hash; }
sub array_union { my ($arrRef1, $arrRef2) = @_; my %hash; @hash{@$arrRef1} = undef; @hash{@$arrRef2} = undef; return keys %hash; }
std::vector::const_iterator itr;
error: expected `;' before "itr"
typename std::vector::const_iterator itr;
#include <unistd.h> #include <stdio.h> int processMemUsage() { int vm = 0; FILE* fp = fopen("/proc/self/stat", "r"); if(fp == NULL) { return vm; } int dummy; char cmd[128], state[8]; fscanf(fp, "%d%s%s%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", &dummy, cmd, state, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy); unsigned long vmSize; fscanf(fp, "%lu", &vmSize); fclose(fp); vm = (int) (vmSize >> 10); return vm; }
Process p; try { p = Runtime.getRuntime().exec("su"); } catch(IOException e) { e.printStackTrace(); }
$ ./sdCardSpeedTest.sh /mnt/sdcard NOTE: Test might take about 5-10 min depending on your sd-card speed! Please be patient during this time... Evaluating write-BW... 100000000 bytes transferred in 26.371 secs (3792044 bytes/sec) 100000000 bytes transferred in 19.656 secs (5087505 bytes/sec) 100000000 bytes transferred in 20.697 secs (4831618 bytes/sec) 100000000 bytes transferred in 20.086 secs (4978592 bytes/sec) 100000000 bytes transferred in 53.975 secs (1852709 bytes/sec) 100000000 bytes transferred in 28.934 secs (3456141 bytes/sec) Write BandWidth: 3.81448 MBps Evaluating read-BW... 100000000 bytes transferred in 18.844 secs (5306728 bytes/sec) 100000000 bytes transferred in 17.818 secs (5612302 bytes/sec) 100000000 bytes transferred in 17.331 secs (5770007 bytes/sec) 100000000 bytes transferred in 17.301 secs (5780012 bytes/sec) 100000000 bytes transferred in 17.306 secs (5778342 bytes/sec) 100000000 bytes transferred in 17.310 secs (5777007 bytes/sec) Read BandWidth: 5.40803 MBps Cleaning up all the temporary files...
$ ./sdCardSpeedTest.sh /mnt/emmc NOTE: Test might take about 5-10 min depending on your sd-card speed! Please be patient during this time... Evaluating write-BW... 100000000 bytes transferred in 9.372 secs (10670081 bytes/sec) 100000000 bytes transferred in 6.579 secs (15199878 bytes/sec) 100000000 bytes transferred in 6.252 secs (15994881 bytes/sec) 100000000 bytes transferred in 6.321 secs (15820281 bytes/sec) 100000000 bytes transferred in 6.532 secs (15309246 bytes/sec) 100000000 bytes transferred in 6.516 secs (15346838 bytes/sec) Write BandWidth: 14.0415 MBps Evaluating read-BW... 100000000 bytes transferred in 5.168 secs (19349845 bytes/sec) 100000000 bytes transferred in 5.038 secs (19849146 bytes/sec) 100000000 bytes transferred in 4.661 secs (21454623 bytes/sec) 100000000 bytes transferred in 4.671 secs (21408691 bytes/sec) 100000000 bytes transferred in 4.694 secs (21303792 bytes/sec) 100000000 bytes transferred in 4.693 secs (21308331 bytes/sec) Read BandWidth: 19.8165 MBps Cleaning up all the temporary files...
$ ./sdCardSpeedTest.sh /data/local NOTE: Test might take about 5-10 min depending on your sd-card speed! Please be patient during this time... Evaluating write-BW... 100000000 bytes transferred in 6.876 secs (14543339 bytes/sec) 100000000 bytes transferred in 8.566 secs (11674060 bytes/sec) 100000000 bytes transferred in 8.565 secs (11675423 bytes/sec) 100000000 bytes transferred in 6.783 secs (14742739 bytes/sec) 100000000 bytes transferred in 7.617 secs (13128528 bytes/sec) 100000000 bytes transferred in 8.168 secs (12242899 bytes/sec) Write BandWidth: 12.3989 MBps Evaluating read-BW... 100000000 bytes transferred in 5.537 secs (18060321 bytes/sec) 100000000 bytes transferred in 5.641 secs (17727353 bytes/sec) 100000000 bytes transferred in 5.274 secs (18960940 bytes/sec) 100000000 bytes transferred in 5.275 secs (18957345 bytes/sec) 100000000 bytes transferred in 5.268 secs (18982536 bytes/sec) 100000000 bytes transferred in 5.273 secs (18964536 bytes/sec) Read BandWidth: 17.7468 MBps Cleaning up all the temporary files...
Location | Write BW (MBps) | Read BW (MBps) |
---|---|---|
External sd-card | 3.81 | 5.41 |
Internal sd-card | 14.04 | 19.82 |
Phone Memory | 12.40 | 17.75 |
null := SPACE := $(null) $(null) WITHSPACE := A string with spaces REPLACED := $(subst $(SPACE),:,$(WITHSPACE)) default: @echo WITHSPACE = $(WITHSPACE) @echo REPLACED = $(REPLACED)
$ make WITHSPACE = A string with spaces REPLACED = A:string:with:spaces
#include <stdio.h> void isCorrect(int** grid, int N, int sqrootN) { int sum = (N * (N + 1)) >> 1; // all rows for(int i=0;i<N;i++) { int actual = 0; for(int j=0;j<N;j++) { actual += grid[i][j]; } if(actual != sum) { printf("Row '%d' is incorrect!\n", i+1); } } // all columns for(int i=0;i<N;i++) { int actual = 0; for(int j=0;j<N;j++) { actual += grid[j][i]; } if(actual != sum) { printf("Column '%d' is incorrect!\n", i+1); } } // all blocks for(int i=0;i<N;i+=sqrootN) { for(int j=0;j<N;j+=sqrootN) { int actual = 0; for(int a=0;a<sqrootN;a++) { for(int b=0;b<sqrootN;b++) { actual += grid[i+a][j+b]; } } if(actual != sum) { printf("Block starting at '%d,%d' is incorrect!\n", i+1,j+1); } } } } int main(int argc, char** argv) { if(argc == 2) { FILE* fp = fopen(argv[1], "r"); if(fp == NULL) { fprintf(stderr, "Failed to open '%s' for reading!\n", argv[1]); return 1; } int N, sqrootN; int** grid; fscanf(fp, "%d", &N); fscanf(fp, "%d", &sqrootN); grid = new int* [N]; for(int i=0;i<N;i++) { grid[i] = new int [N]; for(int j=0;j<N;j++) { fscanf(fp, "%d", &(grid[i][j])); } } isCorrect(grid, N, sqrootN); for(int i=0;i<N;i++) { delete grid[i]; } delete grid; fclose(fp); } else { fprintf(stderr, "USAGE: %s <file>\n", argv[0]); return 1; } return 0; }
#include <stdio.h> /** * @brief Finds the size of the file (in B) * @param file name of the file * @return if file-open fails, returns a value of -1; else size of the file. */ int sizeOfFile(const char *file) { FILE* fp = fopen(file, "rb"); if(fp == NULL) { return -1; } fseek(fp, 0, SEEK_END); int i = ftell(fp); fclose(fp); return i; }
int main(int argc, char** argv) { if(argc != 2) { fprintf(stderr, "USAGE: %s <fileToBeRead>\n", argv[0]); return 1; } for(int i=0;i<10000;i++) { sizeOfFile(argv[1]); } return 0; }
$ time ./perf.exe perf.exe real 0m2.677s user 0m0.342s sys 0m1.887s $ stat perf.exe File: `perf.exe' Size: 19596 Blocks: 20 IO Block: 65536 regular file .... some more outputs hidden for privacy reasons ....
#include <time.h> #include <stdio.h> int main(int argc, char** argv) { clock_t a, b; a = b = clock(); while(a == b) { b = clock(); } printf("Minimum resolution by 'clock()' = %lf s\n", ((double) (b - a))/CLOCKS_PER_SEC); return 0; }
gcc -o minRes minRes.c
minRes
<resources> <attr name="global1" format="float"/> <declare-styleable name="parent-attr"> <attr name="attr1" format="integer" /> <attr name="global1" /> </declare-styleable> <declare-styleable name="myattr" parent="parent-attr"> <attr name="attr2" format="integer" /> <attr name="attr3" format="enum"> <enum name="name1" value="value1" /> <enum name="name2" value="value2" /> </attr> </declare-styleable> <declare-styleable> <attr name="global1" /> <attr name="attr4" format="boolean"/> </declare-styleable> </resources>
$ make profile printCpuInfo.sh Processor Information: processor : 0 vendor_id : GenuineIntel model name : Intel(R) Xeon(R) CPU X5355 @ 2.66GHz kaprekarnumber -nooutput -profile -limit 10000 Found 17 kaprekar-numbers among first '10000' integers. Took 0.001309 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 100000 Found 24 kaprekar-numbers among first '100000' integers. Took 0.014230 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 1000000 Found 54 kaprekar-numbers among first '1000000' integers. Took 0.188414 seconds to search for self-numbers among these integers. kaprekarnumber -nooutput -profile -limit 10000000 Found 62 kaprekar-numbers among first '10000000' integers. Took 1.616492 seconds to search for self-numbers among these integers.