Skip to content

Commit

Permalink
Give it birth
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Crouzet committed Dec 29, 2016
0 parents commit 131da65
Show file tree
Hide file tree
Showing 31 changed files with 2,236 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
._*
.DS_Store

__pycache__/
build/
dist/
env/
sdist/
wheels/
*.egg-info/
*.egg
*.lprof
*.py[co]

*.sublime-*
4 changes: 4 additions & 0 deletions CHANGES
@@ -0,0 +1,4 @@
v0.1.0 (2016-12-29)
-------------------

* Initial release.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2016 Christopher Crouzet

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,7 @@
include CHANGES
include LICENSE
include README.rst

recursive-include benchmarks *
recursive-include doc *
recursive-include tests *
100 changes: 100 additions & 0 deletions README.rst
@@ -0,0 +1,100 @@
Revl
====

Revl helps to benchmark code for Autodesk Maya.

Upon writing a piece of code for Maya, it might be interesting to know how it
performs under different conditions, such as within scenes that are large or
small, that define a deep DAG hiearchy or a flat one, that use many node types
or only a few, and so on.

Following sets of user-provided commands, Revl can pseudo-randomly generate
Maya scenes with different properties against which the behaviour of a piece of
code can be observed.

The pseudo-random nature of the process can also help revealing potential bugs
by exposing edge cases that were not thought of, thus making it also a good
tool for unit testing.


Features
--------

* generate scenes by running commands a given total number of times.
* fine control over the probability distribution for each command.
* scene generations are reproducible using a fixed seed.
* extensible with custom commands.
* fast (using Maya's API, not the command layer).


Usage
-----

.. code-block:: python
>>> import revl
>>> commands = [
... (2.0, revl.createTransform,),
... (1.0, revl.createPrimitive, (), {'parent': True})
... ]
>>> count = 100
>>> revl.run(commands, count, seed=1.23)
See the ``tutorial`` section from the documentation for more examples.


Documentation
-------------

Read the documentation online at <http://revl.readthedocs.org> or check
their source from the ``doc`` folder.

The documentation can be built in different formats using Sphinx.


Running the Tests
-----------------

A suite of unit tests is available from the ``tests`` directory. You can run it
by firing:

.. code-block:: bash
$ mayapy tests/run.py
To run specific tests, it is possible to pass names to match in the command
line.

.. code-block:: bash
$ mayapy tests/run.py TestCase test_my_code
This command will run all the tests within the ``TestCase`` class as well as
the individual tests which contains ``test_my_code`` in their name.


Get the Source
--------------

The source code is available from the `GitHub project page`_.


Contributing
------------

Found a bug or got a feature request? Don't keep it for yourself, log a new
issue on
`GitHub <https://github.com/christophercrouzet/revl/issues>`_.


Author
------

Christopher Crouzet
<`christophercrouzet.com <http://christophercrouzet.com>`_>


.. _GitHub project page: https://github.com/christophercrouzet/revl
Empty file added benchmarks/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions benchmarks/_loader.py
@@ -0,0 +1,5 @@
import unittest


class BenchLoader(unittest.TestLoader):
testMethodPrefix = 'bench'
51 changes: 51 additions & 0 deletions benchmarks/_runner.py
@@ -0,0 +1,51 @@
import collections
import timeit
import unittest


_clock = timeit.default_timer


def _convertTimeUnit(value):
if not value:
return (value, '')

prefixes = 'munpfa'
level = 0
while value < 1.0 and level < len(prefixes):
value *= 1e3
level += 1

return (value, prefixes[level - 1] if level else '')


def _getBenchName(bench):
return bench._testMethodName


class DummyResult(object):

def wasSuccessful(self):
return True


class BenchRunner(object):

def run(self, bench):
stack = collections.deque((bench,))
while stack:
obj = stack.popleft()
if isinstance(obj, unittest.TestSuite):
stack.extend(bench for bench in obj)
continue

function = getattr(obj, _getBenchName(obj))
start = _clock()
function()
elapsed = _clock() - start
elapsed, unit = _convertTimeUnit(elapsed)
print("%s (%s.%s) ... %.3f %ss"
% (_getBenchName(obj), obj.__class__.__module__,
obj.__class__.__name__, elapsed, unit))

return DummyResult()
75 changes: 75 additions & 0 deletions benchmarks/bench_main.py
@@ -0,0 +1,75 @@
#!/usr/bin/env mayapy

import maya.standalone
maya.standalone.initialize()

import os
import sys
_HERE = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(_HERE, os.pardir)))


import unittest

from maya import OpenMaya

import revl

from benchmarks._loader import BenchLoader
from benchmarks._runner import BenchRunner


class MainBench(unittest.TestCase):

def benchCreatePrimitive1(self):
count = 5000
commands = [
(1.0, revl.createPrimitive,)
]
revl.run(commands, count)

def benchCreatePrimitive2(self):
count = 5000
commands = [
(1.0, revl.createPrimitive, (), {'type': revl.PrimitiveType.POLY_CUBE})
]
revl.run(commands, count)

def benchCreatePrimitive3(self):
count = 5000
commands = [
(1.0, revl.createPrimitive, (), {'name': 'primitive'})
]
revl.run(commands, count)

def benchCreatePrimitive4(self):
count = 5000
commands = [
(1.0, revl.createPrimitive, (), {'parent': True})
]
revl.run(commands, count)

def benchCreateTransform1(self):
count = 5000
commands = [
(1.0, revl.createTransform,)
]
revl.run(commands, count)

def benchCreateTransform2(self):
count = 5000
commands = [
(1.0, revl.createTransform, (), {'name': 'xform'})
]
revl.run(commands, count)

def benchCreateTransform3(self):
count = 5000
commands = [
(1.0, revl.createTransform, (), {'parent': True})
]
revl.run(commands, count)


if __name__ == '__main__':
unittest.main(testLoader=BenchLoader(), testRunner=BenchRunner)
69 changes: 69 additions & 0 deletions benchmarks/run.py
@@ -0,0 +1,69 @@
#!/usr/bin/env mayapy

import os
import sys
_HERE = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(_HERE, os.pardir)))


import collections
import optparse
import sys
import unittest

from benchmarks._loader import BenchLoader
from benchmarks._runner import BenchRunner


def _findBenchs(path, selectors=None):
if selectors is None:
def filter(bench):
return True
else:
def filter(bench):
return any(selector in _getBenchFullName(bench)
for selector in selectors)

out = []
stack = collections.deque(
(BenchLoader().discover(path, pattern='bench*.py'),))
while stack:
obj = stack.popleft()
if isinstance(obj, unittest.TestSuite):
stack.extend(bench for bench in obj)
elif type(obj).__name__ == 'ModuleImportFailure':
try:
# This should always throw an ImportError exception.
getattr(obj, _getBenchName(obj))()
except ImportError as e:
sys.exit(e.message.strip())
elif filter(obj):
out.append(obj)

return out


def _getBenchName(bench):
return bench._testMethodName


def _getBenchFullName(bench):
return '%s.%s.%s' % (bench.__class__.__module__, bench.__class__.__name__,
_getBenchName(bench))


def main():
usage = "usage: %prog [bench1..benchN]"
parser = optparse.OptionParser(usage=usage)

_, args = parser.parse_args()

selectors = args if args else None
benchs = _findBenchs(_HERE, selectors)

suite = BenchLoader().suiteClass(benchs)
BenchRunner().run(suite)


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions doc/.gitignore
@@ -0,0 +1,3 @@
_build
_static
_templates
20 changes: 20 additions & 0 deletions doc/Makefile
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = revl
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@mayapy `which $(SPHINXBUILD)` -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
6 changes: 6 additions & 0 deletions doc/changes.rst
@@ -0,0 +1,6 @@
.. _changes:

Changes
=======

.. include:: ../CHANGES

0 comments on commit 131da65

Please sign in to comment.