Skip to content

Instantly share code, notes, and snippets.

@nasser
Last active April 7, 2020 02:00
Show Gist options
  • Save nasser/49074abf9b2d5e9c2bc789b2ef25a0a1 to your computer and use it in GitHub Desktop.
Save nasser/49074abf9b2d5e9c2bc789b2ef25a0a1 to your computer and use it in GitHub Desktop.
MAGIC proxy
(let [x 0.5
m (proxy [Random clojure.lang.Counted] [100]
(count [] (* x (.Next this))))]
(dotimes [_ 100000]
(.Next m)
(.count m)))
(magic.api/eval
'(time
(let [x 0.5
m (proxy [Random clojure.lang.Counted] [100]
(count [] (* x (.Next this))))]
(dotimes [_ 100000]
(.Next m)
(.count m)))))
;; "Elapsed time: 2.7156 msecs"
(eval
'(time
(let [x 0.5
m (proxy [Random clojure.lang.Counted] [100]
(count [] (int (* x (.Next this)))))]
(dotimes [_ 100000]
(.Next m)
(.count m)))))
;; "Elapsed time: 52.3955 msecs"
using clojure.lang;
using Magic;
using System;
using System.Reflection;
[assembly: AssemblyVersion("0.0.0.0")]
public class proxy63172 : Random, Counted, IProxy
{
private readonly double x;
public proxy63172(long num, double num2) : base((int)num)
{
this.x = num2;
}
public int count()
{
return (int)(this.x * (double)this.Next());
}
public void __initClojureFnMappings(IPersistentMap persistentMap)
{
throw new NotSupportedException();
}
public void __updateClojureFnMappings(IPersistentMap persistentMap)
{
throw new NotSupportedException();
}
public IPersistentMap __getClojureFnMappings()
{
throw new NotSupportedException();
}
}
public class user$fn$63174 : AFunction, Function<object>
{
public override bool HasArity(int num)
{
return num == 0;
}
public override object invoke()
{
double num = 0.5;
proxy63172 proxy = new proxy63172(100L, num);
long num2 = 100000L;
for (long num3 = 0L; num3 < num2; num3 += 1L)
{
proxy.Next();
((Counted)proxy).count();
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment