public void IndexOfTiming() { #if __ANDROID__ const int C = 100; #else // __ANDROID__ const int C = 1000; #endif // __ANDROID__ var total = Stopwatch.StartNew(); using (var array = new JavaInt32Array(Enumerable.Range(0, 10000))) { var io = Stopwatch.StartNew(); for (int c = 0; c < C; ++c) { array.IndexOf(10000); } io.Stop(); var _io = Stopwatch.StartNew(); for (int c = 0; c < C; ++c) { _IndexOf(array, 10000); } _io.Stop(); Console.WriteLine("JavaArray<T>.IndexOf Timing:"); Console.WriteLine("\t JavaArray<T>.IndexOf: {0}", io.Elapsed); Console.WriteLine("\tJavaInt32Array._IndexOf: {0}", _io.Elapsed); } total.Stop(); Console.WriteLine("## {0} Timing: {1}", nameof(IndexOfTiming), total.Elapsed); }
public void Types_GetJniTypeNameFromInstance() { using (var o = new JavaObject()) Assert.AreEqual("java/lang/Object", JniEnvironment.Types.GetJniTypeNameFromInstance(o.PeerReference)); using (var o = new JavaInt32Array(0)) Assert.AreEqual("[I", JniEnvironment.Types.GetJniTypeNameFromInstance(o.PeerReference)); }
public void GetJniTypeName() { using (var o = new JavaObject()) { Assert.AreEqual("java/lang/Object", o.GetJniTypeName()); } using (var o = new JavaInt32Array(0)) { Assert.AreEqual("[I", o.GetJniTypeName()); } }
static unsafe int _IndexOf(JavaInt32Array array, int item) { using (var e = array.GetElements()) { int len = array.Length; for (int i = 0; i < len; ++i) { if (e.Elements [i] == item) { return(i); } } } return(-1); }