Skip to content

Instantly share code, notes, and snippets.

@jonasschneider
Last active June 27, 2017 19:18
Show Gist options
  • Select an option

  • Save jonasschneider/d8bacaec035b99c7f303aafa4f67a0f3 to your computer and use it in GitHub Desktop.

Select an option

Save jonasschneider/d8bacaec035b99c7f303aafa4f67a0f3 to your computer and use it in GitHub Desktop.

Revisions

  1. jonasschneider revised this gist Jun 27, 2017. 2 changed files with 6 additions and 6 deletions.
    6 changes: 6 additions & 0 deletions data.csv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    NSIM,old single,old pool,new
    1,0.11581338301766664,0.13547717899200507,0.16044410099857487
    10,1.128183044027537,0.3996757059940137,0.2795658499817364
    100,11.032577594014583,4.138657283008797,1.8754566199786495
    1000,111.87427679199027,41.56060034601251,19.824343433981994
    10000,1152.050909216021,443.94346881398815,259.57786487799603
    6 changes: 0 additions & 6 deletions data.tsv
    Original file line number Diff line number Diff line change
    @@ -1,6 +0,0 @@
    NSIM old single old pool new
    1 0.11581338301766664 0.13547717899200507 0.16044410099857487
    10 1.128183044027537 0.3996757059940137 0.2795658499817364
    100 11.032577594014583 4.138657283008797 1.8754566199786495
    1000 111.87427679199027 41.56060034601251 19.824343433981994
    10000 1152.050909216021 443.94346881398815 259.57786487799603
  2. jonasschneider renamed this gist Jun 27, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. jonasschneider created this gist Jun 27, 2017.
    24 changes: 24 additions & 0 deletions bench_new.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import mujoco_py
    import timeit


    T = 1000
    NSIM = 100


    def test():
    model = mujoco_py.load_model_from_path(
    "/Users/jonas/code/openai/pymj/xmls/claw.xml")
    pool = mujoco_py.MjSimPool([mujoco_py.MjSim(model)
    for _ in range(NSIM)])
    for _ in range(T):
    pool.step()
    for sim in pool.sims:
    sim.data.qpos
    sim.data.qvel
    sim.data.ctrl
    sim.data.active_contacts_efc_pos

    for i in range(5):
    NSIM = 1 * 10**i
    print(NSIM, timeit.timeit("test()", setup="from __main__ import test", number=1))
    42 changes: 42 additions & 0 deletions bench_old.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    import mujoco_py
    import timeit
    import multiprocessing

    T = 1000
    NSIM = 100


    def f(_):
    model = mujoco_py.MjModel(
    "/Users/jonas/code/openai/pymj/xmls/claw.xml")
    for _ in range(T):
    model.step()
    model.data.qpos
    model.data.qvel
    model.data.ctrl
    model.data.efc_pos[model.data.nefc]


    def test_pool():
    pool = multiprocessing.Pool(processes=8)
    pool.map(f, range(NSIM))


    def test_simple():
    for i in range(NSIM):
    model = mujoco_py.MjModel(
    "/Users/jonas/code/openai/pymj/xmls/claw.xml")
    for _ in range(T):
    model.step()
    model.data.qpos
    model.data.qvel
    model.data.ctrl
    model.data.efc_pos[model.data.nefc]

    for i in range(5):
    NSIM = 1 * 10**i
    simple = timeit.timeit(
    "test_simple()", setup="from __main__ import test_simple", number=1)
    pool = timeit.timeit(
    "test_pool()", setup="from __main__ import test_pool", number=1)
    print(NSIM, simple, pool)
    6 changes: 6 additions & 0 deletions data.csv
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    NSIM old single old pool new
    1 0.11581338301766664 0.13547717899200507 0.16044410099857487
    10 1.128183044027537 0.3996757059940137 0.2795658499817364
    100 11.032577594014583 4.138657283008797 1.8754566199786495
    1000 111.87427679199027 41.56060034601251 19.824343433981994
    10000 1152.050909216021 443.94346881398815 259.57786487799603