Conditions | 9 |
Paths | 20 |
Total Lines | 67 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
70 | function analyze_nvidia() { |
||
71 | $hosts_total = 0; // number of hosts 6.2 or better |
||
72 | $hosts_gpu = 0; // number with an nvidia gpu |
||
73 | $rac_total =0; |
||
74 | $rac_gpu = 0; |
||
75 | $linux_total = 0; |
||
76 | $linux_gpus = 0; |
||
77 | $windows_total = 0; |
||
78 | $windows_gpus = 0; |
||
79 | $model = array(); // name -> count |
||
80 | $ram = array(); // size -> count |
||
81 | $driver = array(); // vers -> count |
||
82 | $ngpus = array(); // ngpus -> count |
||
83 | |||
84 | $hosts = BoincHost::enum("expavg_credit > 10 and serialnum<>''"); |
||
85 | foreach($hosts as $host) { |
||
86 | $boinc_vers = parse_vers($host->serialnum); |
||
87 | if (!$boinc_vers) continue; |
||
88 | if ($boinc_vers->major < 6) continue; |
||
89 | $is_linux = false; |
||
90 | if (strstr($host->os_name, "Linux")) { |
||
91 | $linux_total++; |
||
92 | $is_linux = true; |
||
93 | } else if (strstr($host->os_name, "Windows")) { |
||
94 | $windows_total++; |
||
95 | } else { |
||
96 | continue; |
||
97 | } |
||
98 | $hosts_total++; |
||
99 | $rac_total += $host->expavg_credit; |
||
100 | $gpu = parse_cuda($host->serialnum); |
||
101 | if (!$gpu) { |
||
102 | continue; |
||
103 | } |
||
104 | $hosts_gpu++; |
||
105 | $rac_gpu += $host->expavg_credit; |
||
106 | if ($is_linux) { |
||
107 | $linux_gpus++; |
||
108 | } else { |
||
109 | $windows_gpus++; |
||
110 | } |
||
111 | inc($model, $gpu->model); |
||
112 | inc($ram, $gpu->ram); |
||
113 | inc($driver, $gpu->driver); |
||
114 | inc($ngpus, $gpu->ngpus); |
||
115 | } |
||
116 | |||
117 | $pct = 100*($hosts_gpu/$hosts_total); |
||
118 | echo "ntotal: $hosts_total ngpus: $hosts_gpu ($pct %)\n"; |
||
119 | $pct = 100*($windows_gpus/$windows_total); |
||
120 | echo "Windows: total $windows_total gpus $windows_gpus ($pct %)\n"; |
||
121 | $pct = 100*($linux_gpus/$linux_total); |
||
122 | echo "Linux: total $linux_total gpus $linux_gpus ($pct %)\n"; |
||
123 | |||
124 | $rac_non_gpu = $rac_total - $rac_gpu; |
||
125 | $hosts_non_gpu = $hosts_total - $hosts_gpu; |
||
126 | $a = $rac_gpu/$hosts_gpu; |
||
127 | $b = $rac_non_gpu/$hosts_non_gpu; |
||
128 | echo "Avg RAC: GPU: $a non-GPU: $b\n"; |
||
129 | |||
130 | arsort($model); |
||
131 | foreach($model as $m=>$c) { |
||
132 | echo "$m $c\n"; |
||
133 | } |
||
134 | print_r($ram); |
||
135 | print_r($driver); |
||
136 | print_r($ngpus); |
||
137 | } |
||
163 |