File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
examples/demo-apps/android/MiniBench/app/src/main/java/org/pytorch/minibench Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 11
11
import android .app .Activity ;
12
12
import android .content .Intent ;
13
13
import android .os .Bundle ;
14
- import android .util .Log ;
15
14
16
15
import org .pytorch .executorch .Module ;
17
16
17
+ import java .io .FileWriter ;
18
+ import java .io .IOException ;
19
+
18
20
public class BenchmarkActivity extends Activity {
19
21
@ Override
20
22
protected void onCreate (Bundle savedInstanceState ) {
21
23
super .onCreate (savedInstanceState );
22
- Log .e ("ABENCHBENCHABENCHBENCHABENCHBENCH" , "ABENCHBENCHABENCHBENCHABENCHBENCH" );
23
24
Intent intent = getIntent ();
24
25
String modelPath = intent .getStringExtra ("model_path" );
26
+ int numIter = intent .getIntExtra ("num_iter" , 10 );
27
+
28
+ // TODO: Format the string with a parsable format
29
+ StringBuilder resultText = new StringBuilder ();
30
+
25
31
Module module = Module .load (modelPath );
26
- module .forward ();
32
+ for (int i = 0 ; i < numIter ; i ++) {
33
+ long start = System .currentTimeMillis ();
34
+ module .forward ();
35
+ long forwardMs = System .currentTimeMillis () - start ;
36
+ resultText .append (forwardMs ).append (";" );
37
+ }
38
+
39
+ try (FileWriter writer = new FileWriter (getFilesDir () + "/benchmark_results.txt" )) {
40
+ writer .write (resultText .toString ());
41
+ } catch (IOException e ) {
42
+ e .printStackTrace ();
43
+ }
44
+
27
45
}
28
46
}
You can’t perform that action at this time.
0 commit comments